【问题标题】:In what order do these ZF events run?这些 ZF 事件按什么顺序运行?
【发布时间】:2023-03-04 14:31:01
【问题描述】:

这是一个 Zend 框架问题。

如果我有一个控制器、一个动作助手和一个插件,它们的事件发生的顺序是什么?下面我按照我认为它们发生的顺序列出了我感兴趣的事件。顺序正确吗?

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

  5. 动作助手,init()

  6. 动作助手,preDispatch()

  7. 控制器,init()

  8. 控制器,preDispatch()
  9. 控制器,postDispatch()

  10. 动作助手,postDispatch()

  11. 插件,postDispatch()

  12. 插件,dispatchLoopShutdown()

我突然想到,对于 Action Helper 和 Controller,这对 init() 方法可能会连续运行,然后是一对 preDispatch() 方法,但我认为这不是案例。

感谢您的帮助!

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

    有趣的问题。我认为你是对的,除了 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
    

    希望这会有所帮助。

    【讨论】:

    • 感谢 Marcin,这太棒了!
    【解决方案2】:

    http://www.zietlow.net/zend-framework/zend-framework-ablauf-des-dispatch-prozesses/44/

    有2个链接,里面有关于派送过程的好图。

    【讨论】:

    • 您好 ArneRie,感谢您的回复。序列图很棒,但它只涵盖了 12 个事件中的 8 个。
    猜你喜欢
    • 2015-10-19
    • 2021-11-03
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多