2011-03-29 50 views
7

這是一個Zend框架問題。這些ZF事件以什麼順序運行?

如果我有一個控制器,一個動作助手和插件,做他們的事件發生在什麼樣的順序?下面我按照我認爲它們出現的順序列出了我感興趣的事件。訂單是否正確?

  1. 插件,routeStartup()在
  2. 插件,routeShutdown()
  3. 插件,dispatchLoopStartup()在
  4. 插件,preDispatch()方法

  5. 動作助手時,init()

  6. 動作助手,preDispatch()方法

  7. 控制器時,init()

  8. 控制器,preDispatch()方法
  9. 控制器,執行postDispatch()

  10. 動作助手,執行postDispatch()

  11. 插件,執行postDispatch()

  12. 插件,dispatchLoopShutdown()在

IT運ccurred對我說,當涉及到動作助手和控制器,一對的init()方法可以連續運行,其次是對preDispatch()方法,但我不認爲是這樣。

感謝您的幫助!

回答

7

有趣的問題。我認爲你是正確的,除了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 

希望這會有所幫助。

+0

謝謝Marcin,這太棒了! – 2011-03-29 21:33:55

相關問題