Introduction

MVC stands for Model-View-Controller. Model means data, View means representation and Controller means business logic. MVC was originally described in terms of a design pattern for use with Smalltalk by Trygve Reenskaug in 1979. MVC is a software architecture or we can say that MVC is a design pattern or MVC is a framework. The MVC pattern is a process of breaking an application into three parts: the model, the view, and the controller. A Design pattern is a code structure that allows common coding frameworks to be replicated quickly.

1st.gif

MVC is used in software development; the fundamental principle of MVC is based on the idea that the logic of an application and presentation are separated from each other i.e. MVC is simply a better way of separating the logic of your application from the display. MVC is an design pattern which is used in software programming. In MVC, the model represents data of the application; the view represents presentation logic and the controller represents all our business logic and manages the communication of data and the business rules. The MVC architecture has been used in many programming languages and technologies such as Java, .NET and PHP etc.

The purpose of the MVC pattern is to separate the model from the view so that changes to the view can be implemented, or even additional views created, without having to refactor the model.

A simple way to think of this would be to consider the following:

2nd.gif

Example

A bike is a real-world example of MVC. With a bike you have two views: the interior and the exterior. Both take input from the controller: the driver. The brakes, wheel and other controls represent the model: they take input from the controller (driver) and hand them off to the views (interior/exterior) for presentation.

Model

Model is the first part of the MVC pattern. Model handles all our database logic. The Model may not necessarily have a persistent data store (database), but if it does it may access it through a separate Data Access Object (DAO). The main features of a Model are as follows:

View

Controller

There are many frameworks available which follow the MVC pattern in PHP. Like as Zend Studio framework, CodeIgniter framework, PHP Smart etc. In the next article I will explain the CodeIgniter framework which follows the MVC pattern.

Conclusion

So in this article you saw an introduction to MVC in PHP. In the next article you will see the MVC pattern used in the CodeIgniter framework.

Some Helpful Resources