Simple PHP MVC Framework Example

Today we will discuss how to create MVC sample application in PHP.Because now days in php everybody creating class based structure of application and main problem in class based the all the things is in same function(such as view,model and action).So with help of MVC we will separate all layer.
The MVC stands for Model,view and controller.You can get more information of MVC introduction from Model,View and Controller in MVC

Checkout other Tutorials,

The file structure of MVC application are below:

Step 1: First we will create index.php file,In index file we will get the action from URL.

in above code we have created a link domain1, when we click the domain it will go controller file and action method.

Step 2: We will create base controller file.This file contains all methods which we will use in all controllers, in other words all common controller methods.

Step 3: Now we will create our module controller and extend base controller.

Step 4: Now i am creating base_model class.This class contains all method which is common in all module model class.

Step 5: Lets create our module model file which will extend base model class.

Step 6: How to call model method in controller file.

Step 7: Created a new config.php file which will contain configuration level variable.
Step 8: Created a new common_function.php file.This file contains all helper method which is available in all modules.
Step 9: Finally we will create view file in view folder.This file contains HTML and js related functionality.