We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

404 redirect, controller/action doesnt seems to work

so I do the registering to handle 404 error:

  public function registerServices(\Phalcon\DiInterface $di)
    $di->set('dispatcher', function() use ($di) {
      $dispatcher = new \Phalcon\Mvc\Dispatcher();
      $evManager = $di->getShared('eventsManager');
      $evManager->attach('dispatch:beforeException', function($event, $dispatcher, $exception) {
        switch ($exception->getCode())
          case \Phalcon\Mvc\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
          case \Phalcon\Mvc\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
              'namespace'  => 'Application\My\Controllers',
              'controller' => 'errors',
              'action'     => 'show404'
            return false;
      return $dispatcher;

and now the views/errors/show404.phtml runs - however, controllers/ErrorsController::show404Action win NOT. Interestingly, if I remove/rename show404Action method, it chrashes.

edited Mar '16

Is not a typo?

'controller' => 'error',

And make sure, that you are using the correct namespace n ErrorController, and extends just "\Phalcon\Mvc\Controller".


yea, just a typo, fixed in my post. It still doesnt work :)


Are you using some "ControllerBase" extending the "ErrorController"? Maybe, there is some before() method executing actions before your show404.

Another thing. You cannot access /errors/show404, because it's not been a route.