Yii implements the model-view-controller (MVC) design pattern, which is widely adopted in Web programming. MVC aims to separate business logic from user interface considerations, so that developers can more easily change each part without affecting the other. In MVC, the model represents the information (the data) and the business rules; the view contains elements of the user interface such as text, form inputs; and the controller manages the communication between the model and the view.
Besides implementing MVC, Yii also introduces a front-controller, called
Application, which encapsulates the execution context for the processing
of a request. Application collects some information about a user request and
then dispatches it to an appropriate controller for further handling.
The following diagram shows the static structure of a Yii application:
Static structure of Yii application
The following diagram shows a typical workflow of a Yii application when it is handling a user request:
Typical workflow of a Yii application
http://www.example.com/index.php?r=post/show&id=1and the Web server handles the request by executing the bootstrap script
urlManager. For this example, the controller is
post, which refers to the
PostControllerclass; and the action is
show, whose actual meaning is determined by the controller.
showrefers to a method named
actionShowin the controller class. It then creates and executes filters (e.g. access control, benchmarking) associated with this action. The action is executed if it is allowed by the filters.
Postmodel whose ID is
1from the database.
Found a typo or you think this page needs improvement?
Edit it on github !
MVC is used so much because it simplified application development and maintenance by separating the application into 3 logical components;
model (business logic), view (look and feel) and controller (the "glue").
This is obviously a very simplified description but basically the MVC pattern allows for organized and maintainable code.
Signup or Login in order to comment.