In the PHP chat a link got passed around (see “Deploying MVC on the web” below) and I thought it’s worth to link the multiple MVC related articles by Tom Butler. He is one of those persons who actually leave references after their articles, that’s fine.
What’s fine as well is that he is not shy to offer his own sight on things regardless of the way so far of usage of MVC and realated terminologies that have squashed our minds too far. Probably just the right time for a re-read.
- Model-View-Confusion Part 1: Why the model is accessed by the view in MVC (by Tom Butler; 6 Jul 2010)
- Model-View-Confusion Part 2: Maximising View reusability with View Helpers (by Tom Butler; 9 Jul 2010)
- MVC In PHP Part 1: Hello World (by Tom Butler; 8 Sep 2010)
- MVC In PHP Part 2: Deploying MVC on the web (by Tom Butler; 20 Sep 2010)
- MVVM, MVC it’s all just roman numerals to me (by Tom Butler; 5 Nov 2010)
(by Tom Butler; 6 Jul 2010) MVC is a common subject in the PHP community at the moment. There are a large body of articles, tutorials and code examples on the subject. Most of which deviate from the traditional approach to MVC and subscribe to an approach closer to MVP. Very few of these follow the MVC standard of allowing the view access to the model. Yet this is what they ascribe to be. This article explains why the view should have access to the model and the problems which are created by taking the differing approach commonly used throughout the PHP community. The full article
(by Tom Butler; 9 Jul 2010) Part 1 discusses MVC and explains why the view has access to the model in MVC. Taking this approach, however, is not as simple as it seems. Giving the view access to the model creates a whole new set of problems. The difference is, these problems are easily fixed. This article presents a useful way of fixing the problems while retaining high reusability and flexibility. The full article
(by Tom Butler; 8 Sep 2010) Since writing my article Model-View-Confusion part 1: Why the model is accessed by the view in MVC I have received several e-mails asking me to provide a simple example of MVC in PHP. So I’ve decided to create one. However, my intent is to build up from a very simplistic example and include some of the reasoning behind certain design decisions and considerations involved in deploying MVC on the web.
As stated in my previous article, a lot of other tutorials/articles go off into irrelevant sub-topics. I want to cover pure MVC. As such, you’ll find no discussion of template engines, directory structures, DAO, ORMs or similar in this article. This is pure MVC. From the ground up I’ll explain the original implementation of MVC and why it has to be adapted to work on the web. The full article
(by Tom Butler; 20 Sep 2010) In part 1 I provided a basic example of implementing a standard MVC set up in PHP. The biggest problem with this standard approach on the web is scalability. In the examples, I have explicitly stated which model, view and controller are initiated. Which is fine in the desktop application environment where it was conceived. On the web, however, there are some constraints imposed by the underlying architecture.
A reasonable request would be to substitute the model being used. How can we do this on the web? Have a specific PHP file for each triad, initialising all 3 components? It’s certainly an option, but ties you down to a URI structure and specific PHP files for each task. Then there’s the repeated code.
For example, what about the very common scenario of putting the MVC triad inside an overall site layout? It would require even more repeated layout generation code in each page. What if this layout code has to be updated? That’s a lot of places to change it! Obviously this isn’t viable in any non-trivial project.
How, then, can the script know which model view and controller are needed? The full article
(by Tom Butler; 5 Nov 2010) An exploration of the differences between MVC and MVVM and their relative efficacy for use on the web. In PHP specifically, a definition of MVC has evolved that does not conform to the standard definition of MVC anyway. But is MVC really the best thing to strive for anyway? The full article