The reason why you can't grab the controller as a target of the MvcEvent
prior to EventManager dispatch event (so even attaching to it at higher
than 0 priority) is because this event itself is what makes the Application
aware of what controller is going to be used.

The SharedEventManager listeners can be used instead, like it's done
in EdpModuleLayouts.

The difference is that the main EventManager is triggered by
Application::run(). That makes the DispatchListener come into place and
have it invoke AbstractController::dispatch(). This is when the controller
is set as the event target, and then the SharedEventManager listeners are
triggered, so those listeners have awareness of what controller is going to
return the dispatch result even prior to its 'onDispatch()' method call.

Also, your talking about a "main controller" that forwards to others. Now,
you may have your reasons to do that, but that's generally not recommended.
Controllers should not be altering the MVC flow, their task is just to
deliver a result.
Choosing what controller will be called is a concern of the Router; the
Renderer will deal with the result if needed, i.e. when the result is a
Response the cycle is short circuited by Application::run() instead.

So if I got what you're trying to achieve, you should listen to post-route
to deal with your 'forwarding', and then listen to [pre-render |
post-dispatch | shared pre-dispatch] to deal with your layout selection.

Since the way you deal with pre or post MVC events is actually priority,
that makes any additional event unnecessary. You just have to get the
provided ones right ;)

Hope to be helpful.

Stefano Torresi


2014/1/24 Antoine Hedgecock <antoine.hedgec...@cyant.dk>

> You can always attach a callback with a higher priority!
>
>
> On 24 Jan 2014, at 12:10, Er Galvao Abbott <gal...@galvao.eti.br> wrote:
>
> > There are actually 2 events that occur before the dispatch. See:
> http://framework.zend.com/manual/2.2/en/modules/zend.mvc.mvc-event.html#order-of-events
> >
> > Er Galvão Abbott
> >
> > P.S.: Sorry, dolphin, replied directly to you by mistake)
> >
> > On 01/24/2014 08:33 AM, dolphin wrote:
> >> Will there be in zf2 an event "dispatch.pre"?
> >> I try to explain the meaning of the question. The fact is that when the
> >> controller performs "forward", then the main controller can be obtained
> as a
> >> target only after the additional is executed. However, in real-time as
> first
> >> will executed the main controller. That is, the chain of events does not
> >> correspond to the actual execution time.
> >>
> >>
> >>
> >> --
> >> View this message in context:
> http://zend-framework-community.634137.n4.nabble.com/ZF2-dispatch-pre-tp4661523.html
> >> Sent from the Zend Framework mailing list archive at Nabble.com.
> >>
> >
> >
> > --
> > List: fw-general@lists.zend.com
> > Info: http://framework.zend.com/archives
> > Unsubscribe: fw-general-unsubscr...@lists.zend.com
> >
> >
>
>
> --
> List: fw-general@lists.zend.com
> Info: http://framework.zend.com/archives
> Unsubscribe: fw-general-unsubscr...@lists.zend.com
>
>
>

Reply via email to