Use of Zend's MVC mechanism for analysis (2 ). The code above is pasted to copy the code as follows: $ frontZend_Controller_Front: getInstance (); Zend_Layout: startMvc (array (layoutPathUSVN_LAYOUTS_DIR); $ f
Next, the previous article
Paste the code
The code is as follows:
$ Front = Zend_Controller_Front: getInstance ();
Zend_Layout: startMvc (array ('layoutpath' => USVN_LAYOUTS_DIR ));
$ Front-> setRequest (new Zend_Controller_Request_Http ());
$ Front-> throwExceptions (true );
$ Front-> setBaseUrl ($ config-> url-> base );
$ Router = new Zend_Controller_Router_Rewrite ();
$ Routes_config = new USVN_Config_Ini (USVN_ROUTES_CONFIG_FILE, USVN_CONFIG_SECTION );
$ Router-> addConfig ($ routes_config, 'Routes ');
$ Front-> setRouter ($ router );
$ Front-> setControllerDirectory (USVN_CONTROLLERS_DIR );
$ Front-> dispatch ();
In the previous article, the first two functions, getInstance and startMvc, have been read., The following is the code to continue the analysis
SetRequest ($ request) is used to determine whether the request is inherited from Zend_Controller_Request_Abstract. If yes, assign the value of front _ request to it.
Here we need to know what Zend_Controller_Request_Abstract is, which is an abstract class abstracted by all requests. Zend already provides two implementation classes: Zend_Controller_Request_Http and Zend_Controller_Request_Simple. generally, http requests are used to build servers. Therefore, if your project needs to be re-inherited, Zend_Controller_Request_Http is directly inherited.
The getQuery, getCookie, getRequestUri, getBasePath, getParams, getHeader, and other common Http options that we often use in Zend_controller_Request_Http are already available.
Continue to talk about its base class Zend_Controller_Request_Abstract. the methods of this class include:
Back to code
$ Front-> setRequest (new Zend_Controller_Request_Http (); the constructor of Zend_Controller_Request_Http is called here. The constructor is $ this-> setRequestUri () when it is called for the first time (); many of the setrequesturis directly use the data in the php global variable $ _ SERVER to obtain requestUri.
SetRequestUri: // 172.23.11.160/usvn/item/usvn_test. its requestUri is/usvn/item/usvn_test.
$ Front-> throwExceptions (true); set the internal _ throwExceptions flag to true;
$ Front-> setbaseUrl ("/usvn") is used to set the _ baseUrl attribute inside the front, and call the setBaseUrl of the Request, it also sets the internal _ baseUrl attribute of Zend_Controller_Request_Http.
$ Router = new Zend_Controller_Router_Rewrite ();
$ Routes_config = new USVN_Config_Ini (USVN_ROUTES_CONFIG_FILE, USVN_CONFIG_SECTION );
$ Router-> addConfig ($ routes_config, 'Routes ');
$ Front-> setRouter ($ router );
In the following three lines, the configuration file is used by the Zend Router module, and the router uses setRouter to put it in front.
Last sentence
$ Front-> dispatch ();
This function is also the core function.
This function first registers a plug-in Zend_Controller_Plugin_ErrorHandler with the index of 100 and puts the plug-in sequence at the end.
Step 2 stores a Helper, Zend_Controller_Action_Helper_ViewRenderer, and the index is-80.
The request is instantiated below, and the request is a Zend_Controller_Request_Http type. Set the request baseUrl to the _ baseUrl previously set, that is, "/usvn/item/usvn_test"
Then the response is instantiated, and response is a Zend_Controller_Response_Http ();
The following uses plugins to set the Request and Response. First, the setRequest function of Zend_Controller_Plugin_Broker is called. this function cyclically traverses all the plug-ins managed by the broker and calls the setRequest ($ request) of the plug-in) function (if any ).
Next, initialize the router and set the parameters of the router. The router has already been set before, that is, the Zend_Controller_Router_Rewrite type.
Initialize the distributor dispatcher. this is the first time we see the distributor, Zend_Controller_Dispatcher_Standard class. The distributor will talk about it later.
The following process:
Call the routeStartup of the plug-in to process the request.
Call the route of the router to process the request
Call the routeShutdown of the plug-in to process the request
Call the dispatemediopstartup plug-in to process the request.
Go to the cyclic distribution process
Call the preDispatch of the plug-in to process the request.
Call dispatch of dispatcher to process request and response
Call the postDispatch of the plug-in to process the request.
Out-of-loop distribution process
Call the dispatchLoopShutdown plug-in to process the request
Send response
Pipeline attaches the code as follows: $ front = Zend_Controller_Front: getInstance (); Zend_Layout: startMvc (array ('layoutpath' = USVN_LAYOUTS_DIR); $ f...