Mostafa Solati
Mostafa Solati

Reputation: 1235

Target a specific route in zend framework 2 shared event manager

How to attach shared event manager to a specific route , for example zfcadmin route I want to do this in my "Base" Module not in zfcadmin module , I tried below code but it didn't work :

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

Upvotes: 2

Views: 238

Answers (1)

Ruben
Ruben

Reputation: 5095

I'm not sure what you're trying to accomplish (maybe elaborate), but to check if a specific route is being matched you could listen for the dispatch event and take action. I.e.:

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

Upvotes: 1

Related Questions