我的模型中有一段代码:
public function init(ModuleManager $manager)
{
// Get event manager.
$eventManager = $manager->getEventManager();
$sharedEventManager = $eventManager->getSharedManager();
// Register the event listener method.
$sharedEventManager->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, [$this, 'myFunc'], 100);
}
// Event listener method.
public function myFunc(MvcEvent $event)
{
echo 'it works!';
exit;
}
侦听器被调用。尽管如果我将事件类型更改为 MvcEvent::EVENT_ROUTE,则不再调用侦听器。如何解决?