Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what order do these ZF events run?

This is a Zend Framework question.

If I have a Controller, an Action Helper, 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?

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

  5. Action Helper, init()

  6. Action Helper, preDispatch()

  7. Controller, init()

  8. Controller, preDispatch()
  9. Controller, postDispatch()

  10. Action Helper, postDispatch()

  11. Plugin, postDispatch()

  12. 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!

like image 594
DatsunBing Avatar asked Mar 29 '11 07:03

DatsunBing


2 Answers

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.

like image 118
Marcin Avatar answered Oct 07 '22 23:10

Marcin


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

there are 2 links with good pictures about the dispatch process.

like image 39
opHASnoNAME Avatar answered Oct 08 '22 01:10

opHASnoNAME