Mr.Online
Mr.Online

Reputation: 153

Silverstripe v4 MVC Directories?

I'm Wondering Why There is no "Models / Views / Controllers" Directories Inside SS4 Main Directory? It's Seems Like Everything Should Go Inside "mysite/code" .. How To Accomplish MVC Style?

Upvotes: 0

Views: 132

Answers (1)

bummzack
bummzack

Reputation: 5875

MVC is more of a software-architectural pattern, not how you organize files. There are only a few assumptions the SilverStripe framework makes on how you should organize your code:

Model

With SilverStripe 4, the default code folder for every module is named src or code. In that folder you're free to organize your files as you see fit. Ideally you build your folder structure in a PSR-4 compliant way, so that your folder-names match with your namespaces.

Controllers

Same as with Model classes, you can put your controllers anywhere you want.

There's a default assumption for Page classes though. These expect that the matching controller has the same namespace as the page. So if your page is named: Company\Module\Pages\MyPage, the framework would look for Company\Module\Pages\MyPageController.

You're free to override that though, by implementing the getControllerName method on your Page and return the FQCN for the controller to use.

Views

Also known as "templates" should be in a templates folder. Each module (your mysite folder is also a module) can have a templates folder.

In addition to this, you can have themes. Themes usually bundle templates, css and other assets. In the themes folder you can have multiple theme folders, each one can have a templates folder.

Upvotes: 5

Related Questions