Yii uses the model-view-controller (MVC) design pattern widely used in Web development. The goal of MVC is to separate the business logic from the consideration of the user interface, so that developers can easily change each part without affecting others. In MVC, the model represents information (data) and business rules. The View contains user interface elements, such as text and forms; the controller uses the model-view-controller (MVC) design pattern widely used in Web development for communication between the management model and the view. The goal of MVC is to separate the business logic from the consideration of the user interface, so that developers can easily change each part without affecting others. In MVC, a model represents information (data) and business rules. a view contains user interface elements, such as text and forms. a controller manages communication between a model and a view.
In addition to MVC, Yii also introduces a front-end controller called an application, which indicates the execution context of request processing. The application processes user requests and assigns them to a suitable controller for further processing.
The static structure of the Yii application is shown below:
A typical workflow
A typical Yii application workflow used to process user requests.
1. the user issued an access URL http://www.example.com/index.php? R = post/show & id = 1. the Web server processes this request by executing the entry script index. php.
2. an application instance is created and executed in the script.
3. an application obtains the details of a user request from an application component called request.
4. with the help of an application component called urlManager, the application determines the request controller and action. In this example, the controller is post, which represents the PostController class; the action is show, and its actual meaning is determined by the controller.
5. the application creates an instance of the requested controller to further process user requests. The controller determines that action show points to an actionShow method in the controller class. Then it creates and carries the filters associated with the action (such as access control and benchmark testing ). If the filter permits, the action is executed.
6. The action reads a Post model with ID 1 from the database.
7. The action uses the Post model to render a view named show.
8. Read the view and display the attributes of the Post model.
9. The View executes some small objects.
10. the rendering result of the view is inserted into a layout.
11. the action completes the rendering of the view and presents it to the user.