Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>IANAPHPD (I Am Not A PHP Dev) but the perspective of a general programming language (Java/C#) developer might be helpful. To me, one of the benefits of MVC is to promote code reuse when you have core business logic and infrastructure that needs to be presented with multiple UIs. For example, an order management system that has a web interface as well as a desktop interface. In this case, that core logic is the Model. Each of the three interfaces have there own Views and Controllers. In C#, it is trivial to structure your code such that the core logic is in a set of packages/assemblies that are referenced from a desktop UI project as well as a web application project.</p> <p>I think in these terms even when I'm pretty sure a particular app will not need another UI. When I'm trying to decide if something should go in the model or the controller, I <strong>ask myself if that functionality should be reusable from another UI</strong>.</p> <p>This is a somewhat unnatural way of thinking of PHP code, since PHP is tied so tightly to the web platform (as far as I know). Regardless, this way of thinking still holds (Separation of Concerns and Don't Repeat Yourself) can still be applied: <strong>a secondary "UI" PHP could support would be a web service API</strong>. If a feature should be available to both a website and a web service API, then it should be exposed in the Model.</p> <p>You may or may not be interested, but overall, this way of thinking integrates perfectly with Domain-Driven Design.</p> <p>Note: Though all the UIs supported by PHP are web-based, I'd still be wary of putting web-specific concerns into the model (anything related to browser sessions, cookies, hit tracking, etc), primarily since those concerns are presentation-centric and not business-centric, and secondarily because that makes it harder to port the system piecemeal to another language/platform for whatever reason later.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload