Home  >  Article  >  Backend Development  >  Yii Framework Official Tutorial Supplement 4 - Basic Knowledge: Model-View-Controller (MVC)

Yii Framework Official Tutorial Supplement 4 - Basic Knowledge: Model-View-Controller (MVC)

黄舟
黄舟Original
2017-02-11 09:30:181356browse



Yii uses the Model-View-Controller (MVC) design pattern widely adopted in web development. The goal of MVC is to separate business logic from user interface considerations so that developers can more easily change each part without affecting the others. In MVC, the model represents information (data) and business rules; the view contains user interface elements, such as text, forms, etc.; the controller manages the communication between the model and the view.

In addition to MVC, Yii also introduces a front-end controller called application, which represents the execution context of request processing. The application handles the user's request and dispatches it to an appropriate controller for further processing.

The following diagram shows the static structure of a Yii application:

A typical workflow

The following diagram shows a Yii application Typical workflow when handling user requests.

  1. The user issues a request to access the URL //m.sbmmt.com/, and the web server handles this by executing the entry script index.php ask.

  2. The entry script creates an application instance and executes it.

  3. The application obtains the details of the user's request from an application component called request.

  4. The application determines the requested controller and action with the help of an application component called urlManager. In this example, the controller is post, which represents the PostController class; the action is show, whose actual meaning is determined by the controller.

  5. The application creates an instance of the requested controller to further handle the user request. The controller determines that the action show points to a method named actionShow in the controller class. It then creates and maintains filters associated with the action (e.g. access control, benchmarking). If allowed by the filter, the action will be executed.

  6. The action reads a Post model with ID 1 from the database.

  7. The action renders a view named show through the Post model.

  8. The view reads and displays the properties 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 rendering of the view and presents it to the user.

The above is the content of Yii Framework Official Tutorial Supplement 4 - Basic Knowledge: Model-View-Controller (MVC). For more related content, please pay attention to the PHP Chinese website (www. php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn