I want want dispatch another controller action when Zf2 raise route not found exception to display my custom page ( i dont want to display a custom error page). I am working on dynamic url from database in Zf2 which will occur only when route not found. i added a event in bootstrap function
$event->attach('route', array($this, 'loadConfiguration'), 2);
in loadConfiguration function i added to load
public function loadConfiguration(MvcEvent $e){
$application = $e->getApplication();
$sm = $application->getServiceManager();
$router = $sm->get('router');
$request = $sm->get('request');
$matchedRoute = $router->match($request);
if (null == $matchedRoute) {
$request_uri = $e->getRequest()->getrequestUri();
$dbAdaptor = $e->getApplication()->getServiceManager()->get('Zend\Db\Adapter\Adapter');
$url_table = new UrlMappingTable($dbAdaptor);
$url_data = $url_table->find($request_uri);
$controller = $url_data['controller'];
$action = $url_data['action'];
$id = $url_data['post_id'];
$original_url = $url_data['original_url'];
$alias = $sm->get('Application\Router\Alias');
$alias->setNavigation($original_url);
if(isset($url_data)){
$url = $e->getRouter ()->assemble (array('controller' => $controller,
'action' => $action ,
'id' => $id,
), array (
'name' => 'myurl'
) );
}
print 'no route match';
}
}
after getting the controller and action i just want the dispatcher to forward this controller.