Alex Rivera | Logout

PHP MVC Best Practices/"Rules" for Success

Asked 2009-11-10T23:58:22.423
12

I'm sure that someone already posted this question; however, I would like to get all kind of recommendations for MVC on PHP. I know there are many experts out there willing to share their knowledge with people who has doubts about their coding best practices.

  • How should you organize your Controller?
  • How should you organize your Model?
  • Should Controller call one Model Method and the Model call submethods or should controller call all Model Submethods?
  • etc.

Hope this helps someone out there (because it'll help me for sure).

Edit
Report

1 Answer

1

For php, I like to use the CodeIgniter framework. It lays the ground work for the MVC set up. The controllers are held in "/controllers" and models are in "/models"

I believe that a controller should call the model and the model should encapsulate as much as it can, using submethods if needed. This makes your code much more adaptive and flexible. Example, today your model is reading from a local database, tomorrow you could be reading from a REST service. The model should return data to the controller and the controller should be naive to what is going on inside of the the model.

answered 2009-11-11T00:30:25.797

Your Answer