Using Zend Framework, I want to attach an event on my Application/Module so that on every dispach event this function will be called, for every module. This is my code:
class Module { public function getConfig() { return include DIR . '/../config/module.config.php'; }
public function onBootstrap(MvcEvent $event)
{
$application = $event->getApplication();
$serviceManager = $application->getServiceManager();
$sessionManager = $serviceManager->get(SessionManager::class);
// Get event manager.
$eventManager = $event->getApplication()->getEventManager();
$sharedEventManager = $eventManager->getSharedManager();
// Register the event listener method onDispatch
$sharedEventManager->attach(AbstractActionController::class,
MvcEvent::EVENT_DISPATCH, [$this, 'onDispatch'], 100);
}
public function onDispatch(MvcEvent $event)
{
// Will perform application wide ACL control based on controller,
// action and user data.
}
}
For some reason my onDispatch is never called, even though the application screens are loaded.
Don't know what am I missing. As far as I know, I need to use the shared event manager to be valid for the whole application.
Help appreciated.