Home arrow PHP arrow Building a Simple MVC-based Framework in PHP 5

Building a Simple MVC-based Framework in PHP 5

In this first part of a series, I develop the first module of a model-view-controller (MVC) driven framework, which happens to be a front controller. By combining this component and a basic .htaccess file, itís possible to route all HTTP requests to the (still-undefined) dispatcher class.

  1. Building a Simple MVC-based Framework in PHP 5
  2. Routing all HTTP requests to the front controller
  3. Defining the frameworkís front controller
  4. Bootstrapping the dispatcher module
By: Alejandro Gervasio
Rating: starstarstarstarstar / 6
June 07, 2010

print this article



As you may know, one of the most popular approaches that can be taken for speeding up the development of PHP applications without having to start coding them from scratch is using either a proprietary or a third-party framework. Yes, nowadays PHP frameworks are available in so many flavors and sizes that you've more than likely already picked one up that neatly suits your particular needs.

Although many of these frameworks donít stick to the schema imposed by a particular design pattern, the vast majority of them have adopted the Model-View-Controller paradigm as a standard that allows users to separate the business and application logic from the visual presentation.

Popular software packages like the Zend Framework, Kohana and CodeIgniter are good examples of frameworks that rely on the functionality offered by the MVC design pattern to build powerful PHP programs. This fact speaks for itself about the usefulness of this pattern, particularly when developing well-structured web applications.

However, you, as a curious PHP developer, may want to make your own way and learn how to build a MVC-based framework all by yourself. If this is the case, then you should start reading this series of articles, since Iím going to explain in a step-by-step fashion how to develop a simple framework in PHP 5. It will follow the structure dictated by the MVC design pattern.

Before I start showing some functional code samples, a word of warning is in order here. First off, this guide wonít encourage you to reinvent the wheel. As I said before, youíre free to choose an existing framework and get the job done in a few steps. Instead, this series is aimed at introducing the key concepts that surround the development of a basic MVC-based framework, including the construction of different components, such as a front controller and an action controller, a router/dispatcher and a database abstraction class, and of course a couple of model and view classes.

In addition, I plan to add to the framework some basic caching and input sanitization capabilities; this will be accomplished in forthcoming articles of the series. And last but not least, to complement the material included in this series, you can download the full source files that comprise this example framework and give it a try:


Now, join me in this educational journey and start learning how to build this MVC-driven framework using PHP 5. Letís go!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- 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: