Creating a Web Page Controller with the HMVC Design Pattern
(Page 1 of 4 )
Welcome to the final installment of a series that shows you how to implement the Hierarchical Model-View-Controller design pattern in PHP 5. This series teaches you how to use the HMVC paradigm to develop an object-based framework whose core components can be easily tweaked and enhanced to suit your own programming requirements.
And now that you know what to expect from this group of articles, I'd like to spend a few moments reviewing the topics that were discussed in the last one, in case you still haven't had the chance to look at it. In that tutorial I built a couple of MVC modules, aimed at independently rendering different sections of a basic web page.
The first of these modules was tasked with dynamically constructing the navigation bar of the page, while that the second one was responsible for building its main section, which will display some fictional news previously fetched from a MySQL database table.
Despite the simplistic and rather trivial nature of those MVC modules, also known commonly as MVC triads, they'll come in handy for demonstrating how a single HTTP request can be mapped to multiple controllers (two, for this sample project), thus implementing a hierarchical version of a regular MVC cycle.
However, the area of responsibility of the corresponding MVC triads is limited to rendering only the aforementioned web page's sections -- in other words, the page's inner layout. Therefore, to render a finished version of this page, it's necessary to build a master template that acts like an "outer" layout.
That's precisely what I'm going to do in this last part of the series. This process will hopefully give you a truly spot-on idea of how to use the HMVC pattern in PHP 5.
Now, let's leave the preliminaries behind and start coding that master web page layout!