Hi all! I have multi-module app like in 'mvc\multiple-shared-layouts' and have two modules, frontend and backend. I'm trying to intercept not found events by setting up dispatcher service inside every module's registerServices() method, but it seems application doesn't even run this method. The idea is to have different not found pages for frontend and backend. How can I achieve it? Here is example of my Frontend module, backend is the same except 'module' definitions.
public function registerServices($di)
{
$di->set('dispatcher', function() {
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach('dispatch', function($event, $dispatcher, $exception){
//The controller exists but the action not
if($event->getType() == 'beforeNotFoundAction') {
$dispatcher->forward(array(
'module'=>'frontend',
'controller'=>'index',
'action'=>'show404'
));
return false;
}
if($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array(
'module'=>'frontend',
'controller'=>'index',
'action'=>'show404'
));
return false;
}
}
});
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);
$dispatcher->setDefaultNamespace('Modules\Frontend\Controllers');
return $dispatcher;
});
$di['view'] = function() {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir(__DIR__ . '/views/');
$view->setLayoutsDir('../../common/layouts/');
$view->setTemplateAfter('main');
return $view;
};
}
Thanks.