Is there a way to listen to the "dispatch" event of forwarded controllers?
ControllerA.php
class ControllerA extends AbstractActionController
{
public function forwardAction()
{
$return = $this->forward()->dispatch('ControllerB'));
return $return;
}
}
ControllerB.php
class ControllerB extends AbstractActionController
{
public function indexAction()
{
return "forwarded";
}
}
Module.php
public function onBootstrap(\Zend\Mvc\MvcEvent $e)
{
$application = $e->getApplication();
$eventManager = $application->getEventManager();
$eventManager->attach('dispatch', array(
$this,
'onDispatch'
));
}
public function onDispatch(Event $event)
{
$controller = $event->getTarget();
var_dump(get_class($controller));
}
Output
ControllerA
Expected / Wanted
ControllerA
ControllerB
probaly you can achieve something similar creating a parent class to your controlers, and storing dispatched controller names in a field. something like this.
After the dispatch, you will have an array in MyAbstractActionController::dispatched with the name of all the classes you have been through
please note that i havent tried this code, some errors can be found, and also you need the code in your module to retrieve the list after the dispatch