pMVC article image

Update: pMVC source code now hosted on GitHub.

pMVC is not a framework nor a class library. It´s a simple MVC model for the PHP plattform.

pMVC is a simple MVC model with structure and separate of concerns in mind. It does not contains all the fancy full-fledged framework stuffs like Zend Framework, Code Igniter or Symfony. But it do contains models, views, controllers, helpers, class autoloading and controller-action-routing.

pMVC is running on PHP 5.6.31 and PHP 7 and above, but future versions will be made for PHP 7.x only. You´ll find the documentation in the source. I´ve tried to comment the code as much as possible.


The story behind pMVC isn´t that complicated. It was created to structure my own PHP based applications. The first embryo was used in my thesis at the university. After that it slowly evolved, one piece at a time, in various of private projects.

At work, I work exclusively with Microsoft technology. Therefore it becomes not so much programming in PHP anymore. There´s simply not enough time. Instead of letting projects languish over time, it feels better to share them with others. pMVC is one of those.

Getting Started

Download from GitHub

pMVC comes in two packages. One minimal containing core files (+ a simple view) only. One containing a simple demo site made with pMVC and the Bootstrap framework.

Core project files Demo site

Source Code

These are the files included, how they are structured in the application and a short description of what they do.

├── Controllers/
├── lib/
│   ├── pMVC/
│       ├── Application.php
│       ├── Controller.php
│       ├── Database.php
│       ├── Html.php
│       ├── IRoute.php
│       ├── Model.php
│       ├── Route.php
│       ├── Url.php
│       ├── View.php
│   ├── .htaccess
├── Models/
├── Views/
├── .htaccess (if running on Apache etc.)
├── config.php
├── index.php
|── web.config (if running on IIS)


This is where you put the controller classes.

The pMVC application class library.

This is where the application starts and library, controllers and models are autoloaded.

This is the abstract base class for all controllers. It connects the view and the model.

This class extends the PDO component and setups a database object. Implemented as a singleton and used by the model base class.

Represents support for rendering HTML controls in a view.

If you´re writing custom routes you have to implement the IRoute interface.

This is the abstract base class for all models. It provides a small set of functions for data access that will make your access calls chainable.

The route contains the logic for mapping a request to a specified controller and action. The route values will be extracted from the URL variable ‘load’. You can build custom routes and pass the route object to the application run method. To do so create a class and implement the IRoute interface.

Contains methods to build URLs within an application.

Is responsible for putting everything together, extract view data and render the final HTML content.

Denies directly access to the lib directory. Delete if running on Microsoft IIS.

Models goes in this folder.

Put views into this folder.

The hypertext access file that will do the rewriting stuff, among other things – running Apache etc. Delete if running on Microsoft IIS.

The main configuration file. Defines constant values like the site template file and database related stuff.

The main file where the application will be initialized.

The server configuration file that will replace .htaccess when running pMVC under Microsoft IIS. Delete if running on Apache.

Execution Life Cycle

To explain the execution process of the pMVC application, I´ve summarize the execution of a page in the list below.


pMVC doesn´t use namespaces at the moment – a legacy from the time when namespaces where not available in PHP (arrived in 5.3.0). To be honest I´m not really sure if I like how namespaces are implemented in PHP. But that´s another story. Will return to this in the future.