PHP – Model View Controller (MVC)

Posted on

MVC, or Model-View-Controller is a pattern that is used in software development. The basic idea behind MVC is to separate business logic from its presentation layer. MVC is the most used pattern in today’s web development. This pattern firstly used in Smalltalk and later adopted and popularized by Java.  At present there are more than a dozen PHP web frameworks based on MVC pattern like Zend framework, Symfony, Cake PHP, Code igniter, Yii framework etc.

The MVC pattern separates an application in 3 modules: Model, View and Controller:

1- The model is responsible to manage the data. it stores and retrieves entities used by an application, usually from a database, and contains the logic implemented by the application.

2- The view (presentation layer ) is responsible to display the data provided by the model in a specific format. It has a similar usage with the template modules present in some popular web applications, like Zend framework, Symfony, Cake PHP, Code igniter, Yii framework etc.

3- The controller handles the model and view layers to work together. The controller receives a request from the client, invoke the model to perform the requested operations and send the data to the View. The view format the data to be presented to the user, in a web application as an html output.

mvc in php
The above figure shows MVC Collaboration Diagram, In which the links and dependencies between figures can be seen.

Leave a Reply

Your email address will not be published. Required fields are marked *