For instance, is it “better” to have one controller per view (page) or to lump many views into a master/main controller
One controller, handling many static pages.
But for non static pages, there is no real true “what is best”, it comes down to a combination of personal preference, your design goals, trade-offs from one method compared to another, etc.
For example, you might have a group of use cases all about Cars for Sale.
At first glance it may seem logical to have a controller called “cars” and then all your methods in that one controller. But when you dig a bit deeper, perhaps this is not the best idea because the controller will end up huge with many methods such as:
- etc etc.
At this point your controller is going to be HUGE with potentially 1000s of lines of code.
It would be better to have a folder in your controllers called “cars” and then break each of the above methods into it’s own controller file. But the trade off of this is that any helpers, libraries, models, etc that you want have to be loaded into each and every controller (or you create a “super car contoller” which auto loads all your assets, sets variables, etc, and have all your “car” controllers extend this super car controller).
I’m building a site about Australian capital cities (well, it’s much more than just that, this is just one section of the site). There are 8 capital cities, so I have 8 folders (called its respective city name) in my base controller folder and each page for each capital city has it’s own controller within its respective folder. They are tiny, just sets a few bread crumb variables and some meta data variable, so I could have very easily loaded them all into one city controller, but I chose this method of doing it for some reasons such as I have a nice URL that suits my needs and SEO goals (I could have used routes to fix this, but that involves extra code (thus potentially extra bugs) and extra http redirects for the user, increasing page load speeds), I know in the future I will have MANY pages, and having them all in one controller would mean I could end up with a massive controller (which means more code for the server to load at compile time), so you could call this “future proofing”.
It all comes down to personal preference, site architectural goals, future proofing, etc etc. It comes with experience, good luck, hope this helped somewhat!!!