Filtering Input Data and Generating HTML Forms with the HMVC Design Pattern
(Page 1 of 4 )
In this fourth part of a nine-part series you will learn how to extend the existing functionality of the HMVC-based framework we're building. Specifically, we're going to add a pair of classes to it that permit you to perform basic sanitation on incoming data and generate simple HTML forms.
The Model-View-Controller design pattern is one of the most efficient paradigms that can be used nowadays for developing web-based programs that maintain their business and application logic isolated from the layer that deals with visual presentation. The schema imposed by this pattern, however, can be taken one step further through a hierarchical usage of it.
Yes, as you may have heard, there exists another design pattern, not surprisingly called Hierarchical Model-View-Controller, which can be considered an “enhancement” of a regular MVC implementation. It allows you to build applications composed of multiple and independent MVC modules, also commonly known as MVC triads.
Essentially, during the normal cycle of operation of a program that uses the MVC design pattern, each HTTP request is routed and dispatched to a single controller, which eventually will invoke one or multiple models and views, thus completing the cycle. However, when the HMVC pattern is used, a single request can produce calls to isolated modules composed themselves of a controller, a model and a view, or in other words, the aforementioned MVC triads.
This hierarchical approach permits you to create applications that are much more modular and flexible than the ones developed using a typical MVC layer, although as with many other design patterns, its implementation in real-world projects isn’t mandatory at all.
Of course, there are many approaches that can be taken to learn how to apply the HMVC paradigm, especially when using PHP 5. But in this particular case, I decided to take one that will demonstrate the use of the pattern through the development of a small, object-oriented framework. To accomplish this goal, in previous chapters of this series I added some core components to this framework, including a front controller and a dispatcher, a request-handling module (this is actually the one that makes it easy to handle MVC triads), and a caching class.
However, to illustrate more precisely how to use the HMVC paradigm with this sample framework it’s necessary to make it a bit more functional. Therefore, in this article I’m going to code a couple of classes that will take care of filtering user-supplied data and helping in the generation of HTML forms.
Now, to learn how these new classes will be created, click on the link below and start reading!