Hi David, Keep in mind that you are working with the Zend\Mvc\Application's EventManager instance. Try and follow the code execution in the Application::run() function, to see when and why different events fire.
I would hazard a guess and say that you are accessing a controller in the MyModule, and not in the main Application module. If you run a controller from the Application module, you will then see the 'shared event from application' message show instead of from mymodule. The reason this is happening is because the shared event manager listener you are attaching is listening for the event identifier of __NAMESPACE__. When the dispatch event gets called against a controller under MyModule, only the listener tied to the namespace of that controller will be fired. The reason you will always see both normal event listener messages is because those listeners are both attached to the dispatch event. I feel I am failing at explaining this, can you add me on Skype? Cheers, Michael Gooden On 10 May 2013 03:41, David Muir <davidkm...@gmail.com> wrote: > I'm getting some weird behaviour with the EventManager and > SharedEventManager when used in the Application module vs other modules. > > Application Module: > > public function onBootstrap(MvcEvent $e) > { > //$e->getApplication()->getServiceManager()->get('translator'); > $eventManager = $e->getApplication()->getEventManager(); > $moduleRouteListener = new ModuleRouteListener(); > $moduleRouteListener->attach($eventManager); > > $eventManager->attach(MvcEvent::EVENT_DISPATCH, function ($event){ > echo 'event listener from application module called' . PHP_EOL; > }); > > $sharedEvents = $eventManager->getSharedManager(); > > $sharedEvents->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, > function ($event){ > echo 'shared event listener from application module called'. > PHP_EOL; > }); > > } > > > My Module: > > public function onBootstrap(\Zend\EventManager\EventInterface $e) > { > > $eventManager = $e->getApplication()->getEventManager(); > $sharedEvents = $eventManager-> getSharedManager(); > > $eventManager->attach(MvcEvent::EVENT_DISPATCH, function ($event){ > echo 'event listener from my module called'.PHP_EOL; > }); > > $sharedEvents->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, > function ($event){ > echo 'shared event listener from my module called'.PHP_EOL; > }); > > } > > > > outputs: > > shared event listener from my module called > event listener from application module called > event listener from my module called > > > Can someone explain why the shared event listener attached via the > Application module never gets called? > > Secondary to this, I've seen some examples attach listeners to the shared > manager, and others attach them to the event manager. When do I use one > instead of the other? > > Cheers, > David > > > -- > List: fw-general@lists.zend.com > Info: http://framework.zend.com/archives > Unsubscribe: fw-general-unsubscr...@lists.zend.com > > >