Modelâ€“Viewâ€“Controller (MVC) is a software architecture, currently considered an architectural pattern used in software engineering. The main aim of the MVC architecture is to separate the business logic and application data from the presentation data.
1) Model: The model object knows all about the data, that is needed, to be displayed. It is the model who is aware about all the operations that can be applied to transform that object. It only represents the data of an application. The model represents data and the rules that govern to and updates of this data. Model is not aware about the presentation data and how that data will be displayed to the browser.
2) View: The view, as the name suggest, represents the presentation of the application. The view object refers to the model. It uses the query method of the model to obtain the contents and renders it. The view is not dependent on the application logic. It remains the same even if there is any change / modification in the business logic. In other words, we can say that it is the responsibility of the view to maintain the consistency in the presentation.
3) Controller: Whenever a user send a request, it always go through the controller. The controller is responsible for intercepting the requests from the view and passes it to the model for appropriate action. After the action has been taken on the data, the controller is responsible for directing the appropriate view to the user. In GUIs, the views and the controllers often work very closely together.
How MVC work in Web Development
- First, the browser send an HTTP request to the web application.
- A dispatcher usually will get this HTTP request and determine which controller to be used. This dispatcher is usually called a Front Controller.
- The controller will receive it and from the data received, determine which model’s are needed, what data is required and what actions are needed on the data.
- The model will retrieve the data and implement any necessary actions. Then, it will return the results to the controller, successful or not.
- The controller, based on the results from the model, will then determine which view should be used and provide the view whatever data is to be published to the browser.
- The view will receive this data, implement any presentation logic to the data, and return it back to the controller.
- The controller will then return the results to the browser.
Posted: August 24th, 2010 under CodeIgniter, MVC, Web Architecture, Web Development.