2009年3月5日星期四

Re: [fw-mvc] postDispatch() runs after _foward

-- Yi Tang <ytang@mbira.com> wrote
(on Thursday, 05 March 2009, 04:31 PM -0600):
> lol.. It is an edge then. we did run into this issue with a special Plugin
> where it renders a special view script based on the current user's identity.
> However there was a _forward called before hand, so that plugin was being
> called twice to do the same thing.
>
> Perhaps not a lot of developers have tried to use the postDispatch hook. Our
> group of developers could be the first ones, or the first ones who had
> noticeable effects. If we weren't rendering something using that plugin, we
> probably wouldn't have noticed either.

Actually, a lot of developers use the postDispatch() hook -- the reason
it was added in the first place was because a number of people -- myself
included -- needed the functionality. I can't say I've ever run into the
issue you describe, however.

Changing the behavior at this point, however, could have unexpected
consequences, so we can't honor a change request for it. You should,
however, look at how the ActionStack and Layout plugins handle such
situations, as they do detection on the request object to determine if
new actions should be run. (ActionStack may actually be the solution to
your double execution issue, by the way -- you could simply push the
action to the stack once, and not worry about it thereafter.)

>
> Matthew Weier O'Phinney wrote:
>
> -- Yi Tang <ytang@mbira.com> wrote
> (on Thursday, 05 March 2009, 11:51 AM -0600):
>
>
> well that actually doesn't work for what we're trying to do. Once
> inside of dispatchLoopShutdown, you can't add anything to the view
> render anymore as the view rendering is already complete. So for now
> we're checking $request->isDispatched() inside of the postDispatch()
> hook.
>
> anyhow, our issue is solved. however whether postDispatch should be
> called when dispatched flag is false is still somewhat likely to cause
> confusions.
>
>
> Potentially. But, honestly, in the 2.5 years since I first added the
> pre/postDispatch() hooks, I've never heard anybody complain about it
> before now -- and it's worked this way all along. :)
>
>
>
>
> Yi Tang wrote:
>
>
> ah, excellent point. thanks.
>
> Hector Virgen wrote:
>
>
> Maybe you should be using the dispatchLoopShutdown() hook if you want
> code
> to run at the end of the dispatch loop.
>
> -Hector
>
>
> On Thu, Mar 5, 2009 at 9:15 AM, Yi Tang <ytang@mbira.com> wrote:
>
>
>
>
> well then, don't you think it's more logical to at least not trigger
> postDispatch() until the dispatch loop is complete? "postDispatch"
> gives the
> connotation that it'll only run after the dispatch loop is complete.
>
> Matthew Weier O'Phinney wrote:
>
> -- Yi Tang <ytang@mbira.com> <ytang@mbira.com> wrote
> (on Wednesday, 04 March 2009, 05:17 PM -0600):
>
>
> It appears the postDispatch hook of controller plugins get triggered
> even with _foward calls, when dispatched is still false. Is it a
> bug or
> intentional? It doesn't seem very logical for it to be intentional.
>
>
> Yes, it's intentional. _forward() sets the "isDispatched" flag of the
> request to false, and that flag is checked for as the conditional
> of the
> dispatch loop. During preDispatch(), it can be used to indicate
> that the
> current action should not be executed, but after that, it is simply
> used
> to hint to the dispatch loop that an additional action needs to be
> taken.
>
>
>
>
>
>
>
>
>
>
>
>

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: