Skip to content

Instantly share code, notes, and snippets.

@weierophinney
Created August 29, 2012 19:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weierophinney/3517979 to your computer and use it in GitHub Desktop.
Save weierophinney/3517979 to your computer and use it in GitHub Desktop.
Example of triggering another dispatch event in ZF2
<?php
use Zend\Mvc\Router\RouteMatch;
// Listener on dispatch.error event
$listener = function ($e) {
$app = $e->getTarget();
$events = $app->getEventManager();
$event = clone $e;
$matches = new RouteMatch(array('controller' => 'Some\Controller\Alias'));
$event->setRouteMatch($matches);
$events->trigger('dispatch', $event);
// to be thorough, you should probably copy some of the logic of Zend\Mvc\DispatchListener
// to ensure you get similar behavior with regards to errors.
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment