I can't make not found error page.
router.php
$router = new Phalcon\Mvc\Router();
$router->removeExtraSlashes(true);
// required for modules.
$router->setDefaultModule('core');
$router->add(
'/{lang:[a-z]{2}}/index/:action/:params',
array(
'module' => 'core',
'controller' => 'index',
'action' => 2,
'params' => 3,
)
);
$router->add(
'/{lang:[a-z]{2}}',
array(
'module' => 'core',
'controller' => 'index',
'action' => 'index',
)
);
services.php
// set dispatcher
$di->set('dispatcher', function() use ($di) {
$evManager = $di->getShared('eventsManager');
$evManager->attach('dispatch:beforeException', function($event, $dispatcher, $exception) {
switch ($exception->getCode()) {
case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(
array(
'module' => 'core',
'controller' => 'error',
'action' => 'e404',
)
);
return false;
}
});
$dispatcher = new PhDispatcher();
$dispatcher->setEventsManager($evManager);
$dispatcher->setDefaultNamespace('Core\\Controllers');
return $dispatcher;
});
index.php
$application = new \Phalcon\Mvc\Application($di);
$application->registerModules(
array(
'core' => array(
'className' => 'Core\\Module',
'path' => APPFULLPATH . '/Module.php',
),
'contact' => array(
'className' => 'Modules\\Contact\\Module',
'path' => ROOTFULLPATH . '/modules/contact/Module.php',
)
)
);
Request the page to /index/action-not-exists action-not-exists is not exists in the index controller. but it is not forward to error page.
"Action 'action-not-exists' was not found on handler 'index'"
This is what i got instead of my 404 page.
How to make 404 error page and use in all modules?
--
update: 01
My source code are here https://github.com/OkveeNet/phalcon-begins
Now i can manage to display error 404 page But i have to add this code in every modules. https://github.com/OkveeNet/phalcon-begins/blob/master/core/Module.php
How to make it work in All modules at once? or How to make it use only main settings?
--
Dear Phalcon, please make it easier to manage error pages just like other frameworks.