The Zend framework handles the flow analysis of an HTTP request

  • 2020-03-31 20:15:03
  • OfStack

< img border = 0 height = 455 Alt = "flow chart of process requests the zend framework" SRC = "http://files.jb51.net/upload/2010-2/20100208080034423.png" width = 764 >

 

1. Firstly, the bootstrap process initializes the resources used in the program

2. Create a Zend_Controller_Front entity, implement the front controller pattern, and this entity class will be responsible for dispatching the HTTP request to the appropriate controller action.

3. The Front controller creates two objects to encapsulate the HTTP request and HTTP reply, Zend_Controller_Request_Http and Zend_Controller_Response_Http, respectively

4. The Front controller will create two objects to realize url routing and dispatching, namely routing and dispatcher, which are respectively responsible for finding the controller and action to be executed by the specified url, and loading the corresponding program file and executing the corresponding method.

5. Through the controller plugin mechanism, Zend_Controller_Action_ViewRenderer will create a view property for the controller's entity class, which is an entity object of Zend_View. It is also responsible for rendering the corresponding template file render into the HTTP response object after the controller action request is processed. Finally, the contents of the response object will be output by the Front Controller to the browser.

6. In step 5, although the template file is located by the ViewRender helper object, it is executed by a member function of Zend_VIew (include into the template file), so all the properties and member functions of the view object in the Controller properties can be used in the template file.

 

The lifetime of an HTTP request is over, and the browser gets the content. When the controller's action specifies a variable to render to the view, it typically interacts with the database through Zend_Db_Table to get the data.

Interacting with a database to process data is called business logic, and the template file also contains logic such as simple loops, which is called display logic.

In the MVC implementation, the Model handles the business logic, the View handles the display logic, and the Controller coordinates the two, so the Controller code should be as simple as possible, it just exists as an agent.


Related articles: