You get a bonus - 1 coin for daily activity. Now you have 1 coin

Typical Yii Model-View-Controller (MVC) application workflow

Lecture



  1. Typical Yii application workflow

Yii uses the Model-View-Controller (MVC, Model-View-Controller) design pattern, which is widely used in web programming.

MVC is designed to separate business logic and user interface so that developers can easily modify parts of an application without affecting others. In the MVC architecture, the model provides data and business logic rules, the view is responsible for the user interface (for example, text, input fields), and the controller provides the interaction between the model and the view.

In addition, Yii uses a front controller called an application, which encapsulates the request processing context. The application collects information about the request and sends it to the corresponding controller for further processing.

The following diagram shows the structure of the Yii application:

Yii application static structure

  Typical Yii Model-View-Controller (MVC) application workflow

1. Typical Yii application workflow

The following diagram describes the typical sequence of processing a user request by an application:

Typical Yii application workflow

  Typical Yii Model-View-Controller (MVC) application workflow
  1. The user makes a request via the URL http://www.example.com/index.php?r=post/show&id=1 , and the web server processes it by running the initialization script index.php .
  2. The initialization script creates an instance of the application and launches it for execution.
  3. The application receives detailed information about the user's request from the request component.
  4. The application determines the requested controller and action using the urlManager component. In this example, the controller is a post , which belongs to the PostController class, and the action is a show , the essence of which is determined by the controller.
  5. The application creates an instance of the requested controller to further process the user's request. The controller determines actionShow show action corresponds to the actionShow method in the controller class. Next, filters are created and applied (for example, access control, benchmarking) associated with this action, and, if filters allow, the action is performed.
  6. The action reads a Post model with an ID of 1 from the database.
  7. The action connects the show view by passing the Post model to it.
  8. The view gets and displays the attributes of the Post model.
  9. The view connects some widgets.
  10. The generated view is inserted into the page layout.
  11. The action completes the presentation and displays the result to the user.

Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Famworks

Terms: Famworks