views:

562

answers:

6

I have a pretty large site, and I am looking for the most time efficient way to manage it (I am the sole coder).

I am trying to devise a very simple MVC structure (i don't want to use a framework) to help keep all my code in order.

For a huge site, is it better to have only one controller to handle all the pages, or is it better and easier to split them up?

If just one, what is a good example of a non-framework controller?

+2  A: 

I would split any logical divisions into different controllers - if it's all static pages, then serve it up with all the same 'static page' controller.

If you have some static pages, a FAQ page (or section), a product list - use a controller for each different section. So the static pages would be pulled from flat files or a database by one controller, the FAQ pages would be generated from a FAQ table by another controller, the products and info would be generated by whatever the source for that is.

Every time the way a page is generated or the data is accessed, use a different controller.

Of course, class inheritance can be used to create the base class with the code needed by any controller.

Not sure what you mean by a non-framework controller - I'd checkout the Zend (gasp) 'Framework', the MVC pattern, and even the controller itself, can be used apart from the rest of the framework.

Tim Lytle
+1  A: 

Typically people split up controllers into controllers focused on specific areas of functionality.

Then they stick a "front-controller" in front of it all, so there's only one entry point to the application. The front-controller's only job is to route incoming requests to the appropriate controller.

Look at the way the Zend_Controller component is set up. It may provide everything you need, and you're free to use it without buying into the complete Zend Framework.

timdev
+1  A: 

It depends how you other parts will work. If you only have one model file then it's probably not worth splitting up the controller. If you can split up the model into sections as well as the controller, then do that.

However, I often find that there's too much overlap between models to separate them. You might have a model for articles, but if you want to display the top 20 articles in a sidebar on other pages, that code should be in the article model - and you're going to need that on every page.

Honestly though, the only way to do it is try it and see. Start with a single entry point, and if it gets too, unwieldy, refactor it into smaller chunks.

DisgruntledGoat
+1  A: 

One router/dispatcher, many controllers would be my advice. Controllers ought to map to URLs, which means differing functionality. A controller will collaborate with different services to accomplish each use case, so one controller for your entire app would become too unwieldy if your app has more than a handful of use cases.

duffymo
if i have a couple hundred pages...how do i do that router? is it just one giant switch() ?
johnnietheblack
Spring does it by mapping URLs to controllers. Maybe you need a mapper like that. A switch will be brittle.
duffymo
+1  A: 

Hi,

Since you plan on making use of your own self made framework, I suggest reading the ff: in order to get acquainted with the MVC framework.

http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/

lemon
http://www.phpro.org/tutorials/Model-View-Controller-MVC.htmlWon't let me post more than 1 url.
lemon
+2  A: 
Arms