What is MVC Architecture?
MVC stands for Model-View-Controller. The standard for building modern application. The whole idea behind MVC framework (MVC Architecture) is to build application in a modular way. Where we have 3 general parts responsible for creating the output. Allowing the interaction with the user. In MVC architecture, a model is responsible for retrieving data from database or other resources. Like web services, rss, etc. While view is responsible for how that data will be represented. Then what about controller? Controller is a glue that links Model and view together. Controller uses model to fetch data from database or other resources and populates view with data returned by model. so MVC architecture completely separates database logic, business logic and presentation logic. That’s the main reason of working in MVC architecture.
Model
Model has the data that is required to render things in the view. So it represents the data that are required for rendering. It also takes over the operation related to the domain. The model is used to do something and get the data.
View
It takes over the display of the applications state. A view takes care of “rendering the pixels on the screen”. It should be as dump as possible. Typically a view class understands one or more model(s). Outputs the information of that model. (A view is not allowed to write in the model.) So the view is aware of the model and knows how to read the data out of it. But never the model should know something about the view!
Controller:
It glues together Model and View.It controls the user interaction with the model and the view. (It’s a thin layer that connects models with their views)
A MVC Architecture for Web Applications therefore normally works this way:
- The request that is send from the browser to the web server, is send to a front controller. This front controller builds a request object. Starts the processing of this request.
- That means Controller Objects are called. Normally action methods in the controller that belongs the current request. This process is called “dispatching”. And this controllers are responsible to return the correct response. Like normal controllers they do:
- The controller loads/modify model objects.
- Pass the model to a view.
- calls the view “render()” method to get the response.
- Normally the view that is returned to the browser consists of a hierarchie of subviews and/or widgets.
Popular Frameworks using MVC Architecture:
- Codeigniter
- Ruby on Rails
- Yii
- Laravel
Pingback: Code Riddles Codeigniter: Getting Started » Code Riddles
Pingback: Ruby on Rails Generate Controller & View via command - Coderiddles
Pingback: Introduction to MVC Architecture - CodeRiddles ...
Pingback: Codeigniter CRUD: Day 1 Create Model » CodeRiddles