In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use the MVC mechanism of Zend. It is very detailed and has a certain reference value. Friends who are interested must read it!
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 ()
After reading the first two sentences of getInstance and startMvc, the following is the code to continue the analysis.
SetRequest ($request) here is to determine whether request inherits from Zend_Controller_Request_Abstract, and if so, assign the _ request of front to it.
Here you need to understand what Zend_Controller_Request_Abstract is, which is an abstract class abstracted by all request. Zend has provided two implementation classes, Zend_Controller_Request_Http and Zend_Controller_Request_Simple. Generally, we build servers based on http requests, so if your project needs to be re-inherited, it usually inherits Zend_Controller_Request_Http directly.
The usual options for Zend_controller_Request_Http such as getQuery,getCookie,getRequestUri,getBasePath,getParams,getHeader, which we often use in Http, are already available.
Move on to its base class, Zend_Controller_Request_Abstract, whose methods contain:
Go back to the code
$front- > setRequest (new Zend_Controller_Request_Http ()); here the constructor of Zend_Controller_Request_Http is called, which is $this- > setRequestUri () the first time it is called; many of the setRequestUri directly use the data in the php global variable $_ SERVER to get the requestUri.
What setRequestUri can learn is how to get requestUri in different servers (especially in the $SERVER in IIS, different combinations of variables have different meanings), such as the url of http://172.23.11.160/usvn/item/usvn_test, whose requestUri is / usvn/item/usvn_test.
$front- > throwExceptions (true); set the internal _ throwExceptions flag bit to true
The $front- > setbaseUrl ("/ usvn") does two things. The first is to set the _ baseUrl property inside the front, and the second is to call the setBaseUrl of Request, which also sets the internal _ baseUrl property of the 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)
The following three lines directly say that the Router module using Zend actually uses the configuration file, and router uses setRouter to put it into the front.
The last sentence
$front- > dispatch ()
This function is also the core function.
This function first registers a plug-in with a Zend_Controller_Plugin_ErrorHandler,index of 100, putting the order of the plug-ins last.
The second step stores a Helper,Zend_Controller_Action_Helper_ViewRenderer,index of-80
The following instantiates that request,request is a Zend_Controller_Request_Http type. And set the baseUrl of request to the _ baseUrl set earlier, which is "/ usvn/item/usvn_test".
Then instantiate that response,response is a Zend_Controller_Response_Http ()
Using plugins to set up Request and Response, you first actually call Zend_Controller_Plugin_Broker 's setRequest function, which iterates through all the plug-ins managed by broker, calling the plug-in's setRequest ($request) function, if any.
Next, initialize router, and set the parameters of router. Router has been set up earlier, which is the Zend_Controller_Router_Rewrite type.
Initialize the dispatcher dispatcher, the dispatcher we saw for the first time, the Zend_Controller_Dispatcher_Standard class. We'll talk about the dispenser later.
The following process:
Call the plug-in's routeStartup to process the request
Call route of router to process request
Call the plug-in's routeShutdown to process the request
Call the plug-in's dispatchLoopStartup to process the request
Enter the process of circular distribution
Call the plug-in's preDispatch to process the request
Call dispatch of dispatcher to handle request and response
Call the plug-in's postDispatch to process the request
Jump out of the circular distribution process
Call the plug-in's dispatchLoopShutdown to process the request
Send response
The above is all the content of this article "how to use the MVC mechanism of Zend". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.