Why MVC?
MVC stands for Model, View, Controller. It is a programing pattern used in developing
web apps. This pattern isolates the user interface and backend (i.e. database interaction from each other. A successful implementation of this lets developers modify their user interface or backend with out affecting the other. MVC also increases the flexibly of an app by being able to resuse models or views over again).
Below is a description of MVC in nutshell.
The Model
The lowest level of the pattern which is responsible for maintaining data.The model deals with the raw data and database interaction and will contain functions like adding records to a database or selecting specific database records. In CI the model component is not required and can be included in the controller.
The View
This is responsible for displaying all or a portion of the data to the user.The view deals with displaying the data and interface controls to the user with. In CI the view could be a web page, ajax data or any other "page".
The Controller
Software Code that controls the interactions between the Model and View.The controller acts as the in between of view and model and, as the name suggests, it controls what is sent to the view from the model. In CI, the controller is also the place to load libraries and helpers.
An example of a MVC approach would be for a contact form.
- The user interacts with the view by filling in a form and submitting it.
- The controller receives the POST data from the form, the controller sends this data to the model
which updates in the database. - The model then sends the result of the database to the controller.
- This result is updated in the view and displayed to the user.


