a digital blog

Java Script, JQuery, MySql, PHP, Tutorial

PHP MVC Framework Tutorial

PHP Custom MVC Framework

This post explains you about mvc framework.

MVC stands for Model View Controller.

The model view controller pattern is the most used pattern for web applications.

M (Model)-: Related With Database Query

V (View):- Related With Templates

C (Controller):- Used for communicating Model and View. A place where we write bushiness logic of our program.

MVC Flow:- Firstly user intersect  with controller. Now controller will call to the appropriate model and model return the data and now controller  pass this data   to appropriate view and flow goes again and again.

So here is a simple source code example for PHP MVC framework.


Download Link   Demo Link


Steps for using this framework:

  • Go to common.inc.php under library folder and define all the paths or for using the default path just paste mvc folder into you root directory.
  • Go to product.php under model folder and change you database setting.
  • And just copy sample database attached with zip file and load it into your database.
  • If you wana create a new controller and just create a new php file and put in undercontroller folder  and remember one thing controller file  name and your controller class will be same and additionally Controller  sufix add on it. Like in this example controller name is product and its class name is productController. Same thing apply in case of model.

Framework  Flow:- 

In the first time when user visit the site,  url is:  www.91weblessons.com/demo/mvc  and when user click to more link url will be www.91weblessons.com/demo/mvc?controller=product&function=detail&id=1

Working of index.php:- index.php is the  entry point of the application, and call everytime whenever user navigate within the website. So firstly we check  that there is any controller call or not, and we check this from query string, so if  $_GET['controller'] is set and $_GET['controller'] is not empty only than we take its value other wise we call the default controller that is product in our case.

Same thing work in case of function. Firstly we check that there is any function  call or not, and we check this from query string, so if  $_GET['function'] is set and $_GET['function'] is not empty only than we take its value other wise call our default function that is listing in our case.

And now if  corresponding controller and function not available  in respective folder and file. application will stop using die statement.

And if all is working fine you can create controller object  and call to its function. Now flow goes to controller.

if(isset($_GET['controller']) && !empty($_GET['controller'])){
     $controller =$_GET['controller'];
     $controller ='product'; //default controller

if(isset($_GET['function']) && !empty($_GET['function'])){
    $function =$_GET['function'];
    $function ='listing'; //default function

$fn = SITE_ROOT.'controller/'.$controller . '.php';
       die($function .' function not found');
    $obj=new $controllerClass;
    $obj-> $function();
    die($controller .' controller not found');


Controller Working (product.php):-

loadView used for loading the view and loadModel is used for loading the model, both the function are define in common.inc.php file

 class productController{
   function __construct() {

 function listing(){

 function detail(){

And now welcome to MVC family.


  1. hey great blog post

  2. Keep up the good work , I read few posts on this site and I believe that your weblog is really interesting and contains sets of wonderful information.

  3. It’s actually a cool and helpful piece of information. I am happy that you shared this useful info with us. Please keep us up to date like this. Thank you for sharing.

  4. I simply want to mention I’m beginner to blogging and site-building and really loved you’re blog site. Almost certainly I’m want to bookmark your blog post . You really come with perfect articles and reviews. Thanks for sharing your web site.

  5. I have been browsing on-line greater than 3 hours lately, but I never discovered any interesting article like yours. It is lovely value enough for me. In my view, if all web owners and bloggers made just right content material as you probably did, the web can be much more useful than ever before.

  6. Creating cool blog is not harder than creating excellent information. But you know that you done both incredibly well. Thank man.

  7. Unique perspective. Thank a lot for doing such a good job. I will definitely check to this site to read more and tell my coworkers about this

  8. Thanks for your personal marvelous posting! I quite enjoyed reading it, you might
    be a great author.I will remember to bookmark your blog and may come back
    in the foreseeable future. I want to encourage you to definitely
    continue your great writing, have a nice afternoon!


Copyright © 91 Web Lessons - a digital blog