In this article, I will explain the terms while checking the relationship between MVC (Model, View, Controller) and Router.
The Router plays a role in determining which function in the application is linked to the URL for which the HTTP request was made. Then, assign one method to the Controller explained next.
The "Controller" acts as a control tower for the MVC pattern. It is responsible for handling HTTP requests sent by users. The HTTP request is linked from Router to one method of Controller. Then, the Controller creates and acquires a Model corresponding to the HTTP request, passes the acquired value to the View, and performs processing. In other words, it is the job of the Controller to issue commands to the Model and View.
"Model" is an entity that interacts with data. According to the command from Controller, it gets information from the database, updates data, writes data, and erases data. Only Model can interact directly with the database.
View defines how the data passed from the Controller will be displayed on the HTML page. This is the web page that will eventually be returned as an HTTP response. The View embeds the appropriate Model selected by the Controller, not just the visual part.
This is summarized in a series of flows. The Router receives the HTTP request and associates it with the appropriate action. Did the Controller execute that action, instruct the Model or Veiwa, and return the View as an HTTP response?
Recommended Posts