Monday, September 21, 2015

Basic MVC Architecture

Hello people, In this post I would like to give a basic introduction to what is MVC architecture is, If you are starting to do a project using codeIgniter, you should have to have an idea about this architecture. Most people fail in early parts as they don't have a proper knowledge in this architecture. 


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.

  1. The user interacts with the view by filling in a form and submitting it.
  2. The controller receives the POST data from the form, the controller sends this data to the model
    which updates in the database.
  3. The model then sends the result of the database to the controller.
  4. This result is updated in the view and displayed to the user. 
 So guys that's it for this post. Hope you got an idea about MVC architecture an hoe it works.

No comments:

Post a Comment