Adding a Class to Parse Views to an HMVC Design Pattern Framework
(Page 1 of 4 )
In this sixth installment of a nine-part series on the hierarchical MVC design pattern, I added to the HMVC-based framework a class for parsing view files. After coding this last core component, we've completed the development of the framework.
When it comes to developing modular, well-structured web applications with PHP 5, one of the most efficient approaches is applying the Hierarchical Model-View-Controller design pattern (also known by its acronym as HMVC). It is in general considered an enhancement of a typical MVC implementation, where a single HTTP request can be mapped to multiple, independent MVC triads.
So if you’re a PHP developer who has already mastered the basics of using the MVC pattern and want to learn how to use the hierarchical version of it, then start reading this series of articles. Its tutorials guide you through the development of a basic object-oriented framework, comprised of a stack of simple classes that can be easily grouped under a fully-functional HMVC layer.
Having introduced you to the main subject of this multi-part series, it’s time to quickly review the topics discussed in the previous tutorial. Essentially, in that article I added a generic model class to the framework. This class, in accordance with the schema followed by the MVC paradigm, should be used exclusively for handling the data layer, in this specific case represented through one or more MySQL tables.
Described in simple terms, the model was capable of performing CRUD operations against a selected database table by using a basic MySQL driver, which was developed in an earlier chapter of this series. Also, it’s valid to stress that the method of the model responsible for fetching all of the rows from the table in question cached these rows over 60 seconds, which was accomplished through the corresponding cache class.
So far, so good. Now that this sample framework has been provided with the ability to use different models, where each is bound to a single MySQL table, one would feel inclined to think that it’s possible to rely on its functionality to build applications under the HMVC schema.
Not so fast. There are still some core components of the framework that need to be created. This includes a class that parses view files (or templates) in a pretty painless fashion. Therefore, in the next few lines I’m going to create that view class, and finish building this example framework.
Ready to tackle the development of the aforementioned view-parsing class? Then let’s get started!