Home arrow PHP arrow Developing the Router/Dispatcher Class for a Simple MVC-based Framework in PHP 5

Developing the Router/Dispatcher Class for a Simple MVC-based Framework in PHP 5

In this second part of the series, I add another crucial component to this example MVC-driven framework. It's a basic router/dispatcher class. While the incorporation of this brand new module turns the framework into a more functional piece of code, there are other components that still need to be developed.

TABLE OF CONTENTS:
  1. Developing the Router/Dispatcher Class for a Simple MVC-based Framework in PHP 5
  2. Review: start building the MVC-based framework
  3. Building the router/dispatcher class
  4. Listing the framework’s partial source code
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
June 08, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Given the huge number of MVC-driven PHP frameworks available these days, which come loaded with lots of powerful features aimed at speeding up the development of web applications, it’s fair to think that building software packages like these may be a difficult and demanding task.

While this is undoubtedly valid if you’re planning to build a full-featured framework packed with all the bells and whistles, developing a simple stack of libraries that can be put to work under the schema imposed by the Model-View-Controller design pattern is much easier than you might think.

Of course, with such a great variety of frameworks available and ready to use right out of the box, building one from scratch may seem to be a pretty pointless task. However, it’s possible that you may want to grasp the basics of this process, or simply wish to expand your existing background and learn how to implement the MVC pattern within a concrete project.

If this is the case, then this article series will be useful to you. Through its tutorials you’ll learn how to create a simple, extensible MVC-based framework in PHP 5. You can use it either as a starting point for building your own killer framework, or simply for better understanding the underlying logic of existing frameworks.

Now it's time to review the concepts that were deployed in the first chapter of this series. In that tutorial I started building the first component of this basic MVC framework, that is its front controller. It was responsible for redirecting all HTTP requests to the “index.php” file, as well as for autoloading classes on demand and handling exceptions.

In addition, the front controller was tasked with bootstrapping a router/dispatcher class, even though the definition of this module hasn’t been shown yet. So, in the following lines I’m going to develop this class, thus adding a new component to the framework.

Now, it’s time to leave the preliminaries behind and start coding the router/dispatcher class. Let’s go! 



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: