Miscellaneous Code

  Home arrow Miscellaneous Code arrow Dispatching Requests to MVC Triads wit...
MISCELLANEOUS CODE

Dispatching Requests to MVC Triads with the Hierarchical MVC Design Pattern
By: Alejandros Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2010-02-24

    Table of Contents:
  • Dispatching Requests to MVC Triads with the Hierarchical MVC Design Pattern
  • Review: the partial source files of the HMVC-based framework
  • Routing and dispatching HTTP requests with a basic dispatcher class
  • Adding a basic HMVC layer to the framework with a request-handling class

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Dispatching Requests to MVC Triads with the Hierarchical MVC Design Pattern


    (Page 1 of 4 )

    In this second part of a series on the hierarchical model-view-controller design pattern, I demonstrate how to implement a simple HMVC layer within the sample framework we're developing. This feature was incorporated via a basic request-handling class, which you’re free to improve and extend at will.

    As you may already know, the use of the Model-View-Controller design pattern can be of great help in building web applications that keep their business and application logic isolated from the layer responsible for handling visual presentation.

    Now an architectural standard adopted by many modern, well-established PHP frameworks, the MVC design pattern gives developers the functionality required to create web-based programs that are easier to maintain and scale -- although this isn’t a silver bullet that avoids in all the cases the hazards of poorly-written code.

    Armed with a set of impressive features, it seems at first glance that there's no way to enhance the implementation of the MVC paradigm even further. In reality, this first impression may be rather misleading. In fact it's possible to implement an improved variation of this pattern called the Hierarchical Model-View-Controller pattern, or expressed in short words, simply HMVC.

    Now you may be wondering what the difference is between a regular MVC implementation and one that uses the HMVC schema. Well, in the first case, an application will always map every single HTTP request (when possible) to only one controller, while in the second scenario the same request can be directed to sets of independent MVC modules, commonly known as MVC triads. This approach  offers greater flexibility and scalability.

    Undoubtedly, the theory behind the HMVC design pattern sounds quite complex and hard-to-grasp to a beginner, but in practice, a concrete implementation of it is much easier to achieve than you may think. This concept was partially demonstrated in the first chapter of the series; in that tutorial I started building a basic object-oriented framework in PHP 5, which relied heavily on an HMVC layer to do its business.

    Admittedly, the framework in its current state does nothing particularly useful, since it’s comprised of an “.htaccess” file that redirects all HTTP requests to the front controller, in this case represented by an “index.php” file. However, in the next few lines I’m going to add to the framework a couple of additional classes that will set up the architecture required for routing requests to modular MVC triads.

    Want to learn how this will be accomplished? Then click on the link below and start reading right now!

    More Miscellaneous Code Articles
    More By Alejandros Gervasio

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap