A Sample Web Application with the HMVC Design Pattern
(Page 1 of 4 )
In this seventh part of a nine-part series on the hierarchical model-view-controller design pattern, I start building an example MySQL-driven application. Its main task will consist of displaying a simple web page with data fetched from two different database tables.
Frankly speaking, learning the key concepts that surround the implementation of the Model-View-Controller paradigm in PHP 5 can be a pretty challenging task, particularly for those programmers taking their first steps in the huge (and sometimes esoteric) arena of design patterns. While a few, like Singleton or Factory, are relatively simple to grasp, the MVC pattern presents a steeper learning curve, as it requires modifying and restructuring the way that web applications should be developed.
However, not everything is so intimidating and scary when it comes to mastering the foundations of this architectural pattern. The web is full of tutorials and resources that offer a friendly and spot-on introduction to it, thus making it easier to grab its ins and outs. What's more, many well-established PHP frameworks available nowadays rely heavily on an MVC layer to leverage their full potential; taking a close look at them can be of great help in getting familiar with the pattern's basics as well.
Yet, one of the neatest things about the MVC paradigm is that it can be taken one step further through a hierarchical implementation, not surprisingly called the "Hierarchical Model-View-Controller" pattern. The HMVC pattern permits you to map single HTTP requests to multiple MVC modules, known in programming jargon as MVC triads.
The benefits to using the HMVC approach are many and remarkable, since its intrinsic nature allows you to build programs that are (at least in theory) easier to maintain and scale. Of course, it's fair to say that creating applications that will work under an HMVC schema isn't always a silver bullet that will prevent you from writing poor code -- which applies to others areas of web development as well.
However, the HMVC design pattern is indeed an approach worth looking at, and in this group of tutorials you'll learn how to apply it within the context of an object-oriented framework that can be easily enhanced through your own improvements and tweaks.
In the last tutorial I finished building the aforementioned framework, so it's time to give it a try and see if it's really capable of running under a fully-functional HMVC schema. With that premise in mind, in the following lines I'm going to use it for building a basic MySQL-driven program, which will generate a dynamic web page through a couple of independent MVC triads.
To learn more about how this sample program will be developed, go ahead and begin reading!