YII model-view-controller (MVC) design mode

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.