-- David Rogers <[EMAIL PROTECTED]> wrote
(on Friday, 25 July 2008, 09:01 AM -0700):
> Matthew Weier O'Phinney-3 wrote:
> > 
> >     5.  dispatchLoopStartup()
> >         * call plugins registered with this hook
> >         6.  preDispatch()
> >             * call plugins registered with this hook
> >         7.  Dispatch action
> >             8.  action helper preDispatch()
> >             9.  action controller preDispatch()
> >             10. action method
> >                 * UNLESS a _forward() or redirect has occurred
> >             11. action controller postDispatch()
> >             12. action helper postDispatch()
> >         13. postDispatch()
> >             * call plugins registered with this hook
> >         /* repeat 6 - 13 as necessary */
> >     14. dispatchLoopShutdown()
> >         * call plugins registered with this hook
> >     15. send response
> > 
> 
> First, I didn't realize that dispatchLoopStartup() and
> dispatchLoopShutdown() were available hooks for plugins. 

It's clearly stated in the documentation:

    http://framework.zend.com/manual/en/zend.controller.plugins.html

:)

> Second, it would be noteworthy to indicate that plugins and helpers
> registered are triggered _prior_ to the preDispatch() method and
> _after_ the postDispatch() method in the Controller.

While this is documented, it could be clearer. Please post an issue
regarding this.

> I'm still a little unclear on how the _forward() method is triggered... It
> seems to be outside of the regular flow but dependent on when the request
> occurs. Later in your response:

I use the word _forward() to simply mean the resetting of the
isDispatched() flag in the request object. When performing it from
within an action controller, you use the method _forward(); elsewhere,
you need to call setDispatched(false) on the request object (preferably
also resetting one or more of the action, controller and/or module names).

> Matthew Weier O'Phinney-3 wrote:
> > _forward() does two things. If called in preDispatch() (any of them), it
> > will halt execution of the current action, and cause a new iteration of
> > the loop. When called during an action or during postDispatch() (any of
> > them), it will trigger an additional iteration of the dispatch loop. 
> 
> I presume this has to do with the method by which the _forward() method
> performs its magic, then? Altering the action in the Request object in
> preDispatch(), which occurs before the Dispatcher calls the action method on
> the Controller, effectively alters the action to be performed, and
> unflagging isDispatched triggers the Dispatcher to run through the whole
> dispatch loop again. 

Correct. As noted above, _forward() is a method specific to the action
controller, while you can set the dispatched flag of the request object
anywhere. Internally in the dispatch loop, we check to see if the flag
is false, and if so, we call 'continue' to force a new iteration of the
loop. Inside the action controller's dispatch() method, we do similarly,
only instead just call 'return', which returns to the dispatch loop.

> If the forward call is made in preDispatch(), however, it seems like pushing
> through another dispatch loop is undesirable, since all we really wanted was
> to deflect one action to another, whether in another Controller, Module, or
> the same. I can understand running preDispatch() again for the new action,
> but completing the current dispatch loop and running another one seems
> unnecessary and borderline undesirable.

Actually, this is _very_ much by design. It simplifies the logic, and
keeps the loop self-consistent -- preDispatch() is
called for each and every action that is marked to dispatch, and
postDispatch() is called for every successfully completed action. 

I think you're confusing the purpose of pre/postDispatch() with the
purpose of dispatchLoopStartup/Shutdown(), which each run once per
_request_.

> When called in the action or postDispatch() methods, the Dispatcher ignores
> the isDispatched flag until it hits its own postDispatch()...? Is that
> correct?

Correct.

> My original understanding of _forward() (which I now understand to be
> incorrect), based on the documentation, was that it immediately interrupted
> the dispatch loop and reinitiated it with the new action (and optional
> Controller and Module specification). 

That _is_ correct. I think you're just confusing the purpose of
pre/postdispatch() with dispatchLoopStartup/Shutdown().

(BTW, you need to call 'return $this->_forward(...)' -- otherwise
execution of the action will continue.)

> Again, maybe my current (corrected) understanding of the flow needs
> adjustment. Please correct further, if necessary.
> 
> 
> Matthew Weier O'Phinney-3 wrote:
> > 
> > If you feel this could be made clearer in the manual, please open an
> > issue;
> > ideally, please submit a patch to the manual docbook.
> > 
> 
> I do love clarifying things, so I'll definitely do so...! I love this
> project dearly (been on since 0.6), and I'm eager to contribute something
> meaningful to it!
> 
> Again, thanks a ton for your insight, Matthew!
> 
> David @ OrlandoPHP.org
> -- 
> View this message in context: 
> http://www.nabble.com/Reagrding-the-current-Dispatch-process...-tp18635886p18654666.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
> 

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to