Custom 404 Page

So i'm trying to add a router to a custom 404 page but there's some few problems :

1 - index will not display anything if not inputed :

2 - if i go to a page that does not exists it justs says that the controller does not exist yet .

Routes :

$di['router'] = function () {

$router = new Router();


    'module'        => 'frontend',
    'namespace'     => 'Frontend\Controllers',
    'controller'    => 'error',
    'action'        => 'show404'

$router->add("/admin", [
    'module'     => 'backend',
    'namespace'  => 'Backend\Controllers',
    'controller' => 'index',
    'action'     => 'auth',
return $router;


namespace Frontend\Controllers;

class ErrorController extends ControllerBase
public function indexAction()


public function show404Action()
    echo "132";



Hey man

This is tip, if is true you can share here

edited Mar '15


I had a bit of headache with this problem too and I ended up doing it beforeException in bootstrap

    $response = new \Phalcon\Http\Response();
    $di->set('response', $response);

    $eventsManager = new \Phalcon\Events\Manager();

    $dispatcher = new \Phalcon\Mvc\Dispatcher();

        function($event, $dispatcher, $exception) use ($response)
            switch ($exception->getCode()) {
                case \Phalcon\Mvc\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                case \Phalcon\Mvc\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                    // since you can't do forward between modules, we use a permanent redirect
                    $response->redirect('error/show404', false, 301);
                    return false;

    //Bind the EventsManager to the Dispatcher

    $di->set('dispatcher', $dispatcher);

Or you can take a look here. It works, but since you remove the default routing behavior (new Router(false)) you have to define all the routes yourself or you get a 404 page.

You can further read about this:

use this simple solution instead (just add notFound route to your router):

$router = new Phalcon\Mvc\Router();

// add routes .....

  'module' => 'default',
  "controller" => "error",
  "action" => "notFound"

// blah blah blah ....

$di->set('router', $router);

that's what he already said that he tried and doesn't work because of the default routing behavior. The default route is looking for a controller and an action; when the controller can't be found you get an error and not a not found header. Read the links that I provided and you'll understand.