Yii Framework Official Tutorial Supplemental Article 4--Basics: Model-View-controller (MVC)

Source: Internet
Author: User
Tags yii



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

In addition to MVC, Yii introduces a front-end controller called an application that represents the execution context of the request processing. The app processes the user's request and dispatches it to an appropriate controller to continue processing.

The following shows the static structure of the YII application:

A typical workflow

Shows a typical workflow for a YII application to handle user requests.

    1. The user sends a request to access the URL http://www.php.cn/, and the WEB server processes the request by executing the portal script index.php.

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

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

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

    5. The app creates an instance of the requested controller to further process the user request. The controller determines the action show pointing to a method named Actionshow in the controller class. It then creates and holds the filters associated with the action (for example, access control, benchmark). If the filter is allowed, 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 rendered result of the view is inserted into a layout.

    11. The action finishes rendering the view and renders it to the user.

The above is the official Yii Framework Tutorial Supplement 4--Basics: Model-View-controller (MVC) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.