Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper Design of a MVC Project [closed]

I've been using Kohana for a couple months now, and am still relatively new to the MVC style of organizing your code/presentation/db-layer. Unfortunately, while there is plenty of documentation on how to create a controller, establish a view, and interact with a db via a model, I've not found many resources that deal with clean, and suggested development patterns.

Let me give a quick example:

My latest project has one controller, because I'm not sure if I should be making many more than that...or when I should make a new one. How exactly do I determine when a new controller is needed, along with when a new model is needed?

like image 475
Sampson Avatar asked Jun 19 '09 14:06

Sampson


1 Answers

I'd suggest you to have a look at the resource oriented architecture, first. This won't give you any direct guidelines of how to organize your code. However, when thinking in terms of resources life is more easy when it comes to deciding whether or not to create a new controller. Once you manage to identify a resource in your system, it's usually a good thing to create a model plus a controller for it - although, this is just a rule of thumb.

Some additional points:

  • look for resources and create a model and a controller for each of them (rule of thumb)
  • don't be afraid to create models for resources that don't persist
  • think about controllers as "plumbing" or "wiring" of user to the business domain - their role is to handle user requests and forward the answer back to them - keep them as thin as possible
like image 79
Milan Novota Avatar answered Oct 13 '22 01:10

Milan Novota