在zend框架2共享事件管理器中指定一个特定的路由


Target a specific route in zend framework 2 shared event manager

如何将共享事件管理器附加到特定的路由,例如zfcadmin路由我想在我的"Base"模块中做到这一点,而不是在zfcadmin模块中,我尝试了下面的代码,但它不起作用:

// if admin
$em->attach('zfcadmin', 'route', function ($e) {
    // Do somethings in admin pages
},100) ;

我不确定您想要完成什么(可能需要详细说明),但是要检查特定路由是否匹配,您可以侦听分派事件并采取行动。例如:

$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach(MvcEvent::EVENT_DISPATCH, function($e) {
            echo $e->getRouteMatch()->getMatchedRouteName();
        }, 100);