Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC large websites, use one controller...or many?

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?

like image 530
johnnietheblack Avatar asked Sep 29 '09 00:09

johnnietheblack


People also ask

Can MVC have multiple controllers?

In Spring MVC, we can create multiple controllers at a time. It is required to map each controller class with @Controller annotation.

Should I create a controller for each model?

It is recommended to create new controller class for each model (or for most important ones) of your business logic domain. For example, you can create UserController to manage users of your site.

Can one view have multiple controllers?

Yes, It is possible to share a view across multiple controllers by putting a view into the shared folder. By doing like this, you can automatically make the view available across multiple controllers.

How many controller methods are there?

The controller contains three methods.


1 Answers

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.

like image 150
Tim Lytle Avatar answered Sep 20 '22 22:09

Tim Lytle