MVC is an architectural Design Pattern, used for organizing an application logic into different layers for ease. Basically it comprises of 3 parts such as Model - View - Controller. Let's see each of what it does in detail:
User/ Client ---> Sends Request ---> Controller
Controller: In this MVC architecture,Whenever a User searches/ sends a request to Server, the Server sends that request to the Controller.
So, Typically Controller is responsible for handling the entire requests from client and will tell the rest of Server what to do with request.
It acts as a "MIDDLE MAN" b/w Model & View as it doesn't contain very much code.
So, after getting a request , Controller asks the Model for information based on that request.
It never interacts with data logic directly, should always use Model to perform these operations/actions.
Controller never has to worry about how to handle the data that it sends and receives and instead only needs to tell model what to do & respond based on what the model returns.
After getting the presentation back from View, it sends the same back to User.
Model: Model is responsible for handling all the data logic of a request.
Usually, Model interacts with the database and handles all validations, saving, updating, deleting like CRUD operations of the data.
Model has nothing to worry about handling user requests and what to do on failure/success.
Model only cares about interacting with the data.
View:
After response from Model to Controller , Controller then needs to interact with the View to render the data to the User.
View is only concerned about how to present the data/information that the controller sends it.
It is a template file that dynamically renders HTML based on the data the controller sends it.
View doesn't worry about how to handle the final presentation of the data, but instead only cares about how to present it.
Then it sends back the final presentation to controller.
Points to Remember:
Presentation ( View ) & Logic ( Data ) of data are completely separated which makes Complex Applications much easier.
Model & View never interacts with each other directly. The interactions are always through a Controller.
MVC is an architectural Design Pattern, used for organizing an application logic into different layers for ease. Basically it comprises of 3 parts such as Model - View - Controller. Let's see each of what it does in detail:
Controller: In this MVC architecture,Whenever a User searches/ sends a request to Server, the Server sends that request to the Controller.
So, Typically Controller is responsible for handling the entire requests from client and will tell the rest of Server what to do with request.
It acts as a "MIDDLE MAN" b/w Model & View as it doesn't contain very much code.
So, after getting a request , Controller asks the Model for information based on that request.
It never interacts with data logic directly, should always use Model to perform these operations/actions.
Controller never has to worry about how to handle the data that it sends and receives and instead only needs to tell model what to do & respond based on what the model returns.
After getting the presentation back from View, it sends the same back to User.
Model: Model is responsible for handling all the data logic of a request.
View:
Points to Remember: