You can do this in the onBootstrap
method of your Module.php
as the following:
public function onBootstrap(MvcEvent $e)
{
$em = $e->getApplication()->getEventManager();
$em->attach(\Zend\Mvc\MvcEvent::EVENT_FINISH, array($this, 'doSomething'));
}
and then define a function that doSomething
in your Module.php
as the following:
public function doSomething(MvcEvent $e)
{
// your code goes here
}
You can also add some priority for the callback functions you want to execute if you attached more than one listener on the same event as the following:
$em->attach(\Zend\Mvc\MvcEvent::EVENT_FINISH, array($this, 'doSomethingFirst'), 20);
$em->attach(\Zend\Mvc\MvcEvent::EVENT_FINISH, array($this, 'doAnotherThingLater'), 10);
Higher priority values execute earliest. (Default priority is 1, and negative priorities are allowed.)