I've tried to use the dispatcher loop, followed the examples but I can't get it to work (or it doesn't change anything)...
I've got a releatively complex router (multi-modules + optional language parameter) and I can't seem to get a proper "catchall" to deal with bad urls.
$di['router'] = function() use ($___asConfig) {
//Set to false to be able to use the notFound route
$router = new \Phalcon\Mvc\Router(false);
$router->setDefaults(array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
//Catch all
$router->notFound(array('module' => 'frontend', 'controller' => 'deadend', 'action' => 'notfound'));
//App root and default behaviour
$router->add('/', array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
$router->add('/{lang:([a-z]{2}([_\-][[:alnum:]]{1,8})?)}', array('module' => 'frontend', 'controller' => 'index', 'action' => 'index'));
//prepare a group to manage the same routes including the language param
$withLocale = new \Phalcon\Mvc\Router\Group();
$withLocale->setPrefix('/{lang:([a-z]{2}([_\-][[:alnum:]]{1,8})?)}');
$withLocale->add('/', array('module' => 'frontend', 'controller' => 'index'))->setName('local-lvl-1');
//For each available module, add a set of generic and locale routes + the customs module routes
foreach($___asConfig['modules'] as $sModuleName => $asModuleConf)
{
//First: add generic routes for each module
$router->add('/'.$sModuleName, array('module' => $sModuleName, 'controller' => 'index'));
$router->add('/'.$sModuleName.'/:controller' , array('module' => $sModuleName, 'controller' => 1));
$router->add('/'.$sModuleName.'/:controller/:action', array('module' => $sModuleName, 'controller' => 1, 'action' => 2));
$router->add('/'.$sModuleName.'/:controller/:action/:params', array('module' => $sModuleName, 'controller' => 1, 'action' => 2, 'params' => 3));
//Second step: adding the same routes, adding the locale parameter
// use withLoacl Group, and change param indexes due to regExp at the group level)
$withLocale->add('/'.$sModuleName, array('module' => $sModuleName, 'controller' => 'index'))->setName('local-lvl-2');
$withLocale->add('/'.$sModuleName.'/:controller' , array('module' => $sModuleName, 'controller' => 3))->setName('local-lvl-3');
$withLocale->add('/'.$sModuleName.'/:controller/:action', array('module' => $sModuleName, 'controller' => 3, 'action' => 4))->setName('local-lvl-4');
$withLocale->add('/'.$sModuleName.'/:controller/:action/:params', array('module' => $sModuleName, 'controller' => 3, 'action' => 4, 'params' => 5))->setName('local-lvl-5');
}
$router->mount($withLocale);
return $router;
};
--