In what order do these ZF events run?
This is a Zend Framework question.
If I have a Controller, an Action He开发者_如何学Clper, and a Plugin, what order do their events occur in? Below I have listed the events I am interested in, in the order in which I THINK they occur. Is the order correct?
- Plugin, routeStartup()
- Plugin, routeShutdown()
- Plugin, dispatchLoopStartup()
Plugin, preDispatch()
Action Helper, init()
Action Helper, preDispatch()
Controller, init()
- Controller, preDispatch()
Controller, postDispatch()
Action Helper, postDispatch()
Plugin, postDispatch()
- Plugin, dispatchLoopShutdown()
It occurred to me that, when it comes to the Action Helper and the Controller, the pair of init() methods may run consecutively, followed by the pair of preDispatch() methods, but I don't think this is the case.
Thanks for your help!
Interesting questions. I think you are correct, except 7 and 6 should be oposite. To check it, I debugged a ZF application. This is what I found:
1. $this->_plugins->routeStartup($this->_request); #$this is Zend_Controller_Front
$router->route($this->_request); #$router is Zend_Controller_Router_Rewrite, and method route finds a matching route to the current PATH_INFO
2. $this->_plugins->routeShutdown($this->_request); #$this is Zend_Controller_Front
3. $this->_plugins->dispatchLoopStartup($this->_request); #$this is Zend_Controller_Front
4. $this->_plugins->preDispatch($this->_request); #$this is Zend_Controller_Front
5. $helper->init(); # exectued for helpers by Zend_Controller_Action_HelperBroker
# during making an instance of IndexController.
# Specifically for Zend_Controller_Action_Helper_ViewRenderer
# and Zend_Layout_Controller_Action_Helper_Layout
// IndexControlles has just been instantiated
6. $this->init(); # $this is IndexController
7. $this->_helper->notifyPreDispatch(); # $this is IndexController
8. $this->preDispatch(); # $this is IndexController
$this->$action(); # $this is IndexController (action executed)
9. $this->postDispatch(); # $this is IndexController
10. $this->_helper->notifyPostDispatch(); # $this is IndexController
// Execution of IndexController has just finished
11. $this->_plugins->postDispatch($this->_request); #$this is Zend_Controller_Front
12. $this->_plugins->dispatchLoopShutdown(); #$this is Zend_Controller_Front
// after that response is sent
$this->_response->sendResponse(); #$this is Zend_Controller_Front
Hope this helps.
http://www.zietlow.net/zend-framework/zend-framework-ablauf-des-dispatch-prozesses/44/
there are 2 links with good pictures about the dispatch process.
精彩评论