ZF2-131: 'dispatch.pre' and 'dispatch.post' not triggered within ActionController class

Description

Hi,

I tried to use the 'dispatch.pre' and 'dispatch.post' events of the ActionController in my specialized Constroller class without any luck. It seems that both events are never triggered (or I did not find the place where they are) and thus both events goes into nothing.

My suggestion is to add {{$this->events()->trigger('dispatch.pre', $e);}} into the ActionController::dispatch function to fix it.

Here is my code:

class AdminController extends ActionController {

...

public function __construct() { $events = $this->events(); $events->attach('dispatch.pre' , array($this, 'preDispatch')); }

...

public function preDispatch() { echo 'preDispatch called'; }

... }

Regards, Pascal

Comments

There are no "dispatch.pre" or "dispatch.post" events. Instead, use the priority system -- add a final argument to attach() indicating the priority at which you want the event triggered. Higher priority values trigger earlier (pre), while negative priority values trigger later (post). Default priority, and the priority of the default handler, is 1.

As an example:


$events->attach('dispatch', array($this, 'preDispatch'), 100);

Hi,

Thanks for the hint about the priority within the event dispatcher.

Nevertheless, I think that the comment of the ActionController::dispatch function should be amended to prevent further confusion.

Regards, Pascal