HomePHP Dealing with Views in an MVC-based Framework in PHP 5
Dealing with Views in an MVC-based Framework in PHP 5
In this eighth part of the series, I add to our example MVC-based framework another crucial component. In this case, it's a class that parses data usually injected from a controller and rendered in the form of HTML pages.
As you may know, the Model-View-Controller design pattern has become one of the most widely-adopted standards for developing web programs that maintain application and business logic isolated from visual presentation.
This structural pattern has gained remarkable popularity, especially with PHP developers who already have a firm background in using design patterns for building well-structured and scalable web applications. However, for those who are just learning this specific area, implementing the MVC paradigm in a real-world project can be a pretty challenging task.
In reality, using the MVC pattern with PHP 5 is much easier than you may think. To prove that, in the course of this series of articles I’m going to walk you through the development of a extensible framework that will follow the schema dictated by the pattern.
The purpose for doing this isn’t reinventing anything at all. Instead, you should consider this an educational experience that hopefully will arm you with a more solid understanding of the basics of the MVC pattern and its implementation in a concrete case.
However, if you’ve read the previous tutorials to this point, then it’s safe to say that you’re familiar with the construction of the sample MVC framework mentioned above. In those tutorials I added a set of loosely-coupled classes, aimed at tackling some common tasks such as routing and dispatching user requests to the appropriate controllers and dynamically generating web forms, as well as filtering user input and caching data.
With that decent number of classes available for immediate use, it could be said that the functionality of the framework is fairly acceptable. Or could it? Since the framework will implement an MVC layer, it’s mandatory to create a brand new class that permits you to create and handle views in a painless fashion.
That’s exactly what I’m going to do in the following lines. So, to learn the full details of this process, jump in and start reading!