Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP MVC Best Practices/"Rules" for Success [closed]

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).

like image 603
MarioRicalde Avatar asked Nov 10 '09 23:11

MarioRicalde


1 Answers

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.

like image 50
JoshHighland Avatar answered Oct 11 '22 07:10

JoshHighland