Answer the question
In order to leave comments, you need to log in
How to register listeners in onBootstrap(zf2)?
I'm learning zf2 and ran into a problem.
I need to register EventManager listeners in onBootstrap for logging (and more). But I ran into a problem: when I registered a listener in onBootstrap-e, it fires on a trigger inside onBootstrap, but completely ignores the triggers in the controller. More precisely, it’s not registered at all (var_dump($this->getEventManager())). It just isn't passed to the EventManager in the controller, or those listeners are removed
//$eventManager = $e->getApplication()->getEventManager(); <-- первым вариантом
$sm = $e->getApplication()->getServiceManager();
$eventManager = $sm->get('eventmanager');
/*имя события и функция - не суть, потому что оно прекрасно срабатывает внутри onBootstrap*/
$eventManager->attach('%name%', %function%);
Answer the question
In order to leave comments, you need to log in
ZF2 Shared Modules Event Manager
Try this:
$sem = $e->getApplication()->getEventManager()->getSharedManager();
$sem->attach('Application\Controller\IndexController', '%name%', %function%);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question