Kim*_*nce 7 php zend-framework
这是一个Zend Framework问题.
如果我有一个控制器,一个动作助手和一个插件,他们的事件发生在什么顺序?下面我按照我认为发生的顺序列出了我感兴趣的事件.订单是否正确?
插件,preDispatch()
动作助手,init()
Action Helper,preDispatch()
控制器,init()
控制器,postDispatch()
动作助手,postDispatch()
插件,postDispatch()
在我看来,当涉及Action Helper和Controller时,init()方法对可以连续运行,然后是一对preDispatch()方法,但我不认为是这种情况.
谢谢你的帮助!
有趣的问题.我认为你是正确的,除了7和6应该是对方.为了检查它,我调试了一个ZF应用程序.这是我发现的:
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
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.