Code exemple to attach a logic to a MvcEvent
In module/APIName/Module.php
<?php
namespace APIName;
use Zend\Mvc\MvcEvent;
class Module
{
public function onBoostrap($e)
{
$eventManager = $e->getApplication()->getEventManager();
$serviceManager = $e->getApplication()->getServiceManager();
$eventManager->attach(MvcEvent::EVENT_ROUTE, function($event) use($serviceManager){
$route = $event->getRouteMatch()->getMatchedRouteName();
// Do some stuff, tests, etc...
}, -1100); // set low priority to be sure that route is defined
}
}
Your event will be automatically triggered by the Framework when routing.