Home >Common Problem >Briefly describe the working principle of MVC
Brief introduction to the working principle of MVC
1. The client initiates a request; 2. The server receives the request and parses the request; 3. According to the parsed request, find the corresponding controller and execute the controller; 4. The controller calls the model to obtain data and passes the data to the view; 5. The view renders the data.
The full name of MVC is Model View Controller, which is the abbreviation of model-view-controller. It is a software design model. It uses a method to separate business logic, data and interface display to organize code and gather numerous business logics into one component. While the interface and user interaction need to be improved and personalized, there is no need to rewrite the business logic. , to reduce the encoding time.
V
View refers to the interface that users see and interact with. For example, a web interface composed of html elements, or a software client interface. One of the benefits of MVC is its ability to handle many different views for an application. No real processing happens in the view, it just serves as a way to output data and allow the user to manipulate it.
M
model model refers to a model that represents business rules. Among the three components of MVC, the model has the most processing tasks. The data returned by the model is neutral, and the model has nothing to do with the data format. In this way, a model can provide data for multiple views. Since the code applied to the model only needs to be written once and can be reused by multiple views, duplication of code is reduced. sex.
C
controller controller means that the controller accepts user input and calls models and views to complete the user's needs. The controller itself does not output anything or do any processing. It just receives the request and decides which model component to call to handle the request, and then determines which view to use to display the returned data.
Flow chart:
Recommended tutorial: "PHP Tutorial"
The above is the detailed content of Briefly describe the working principle of MVC. For more information, please follow other related articles on the PHP Chinese website!