$di->set('dispatcher', function () {
$em = new \Phalcon\Events\Manager();
$em->attach("dispatch", function ($event, $dispatcher, $exception) {
// controller or action doesn't exist
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array(
'controller' => 'index',
'action' => 'route404'
));
return false;
}
}
});
$dispatcher = new \Phalcon\Mvc\Dispatcher();
// Set default namespace
$dispatcher->setDefaultNamespace("Your\Controllers");
$dispatcher->setEventsManager($em);
return $dispatcher;
});
IndexController.php
namespace Your\Controllers;
class IndexController {
public function route404Action()
{
}
}