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



I tried to use the 'dispatch.pre' and '' 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


There are no "dispatch.pre" or "" 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);


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