This works for Phalcon 2.0.13.

You can set up a custom 404 controller and method in Phalcon using the Dispatcher. Just replace the CONTROLLER_NAME and METHOD_NAME in the code below with your choice of controller and method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$this->di->set ( 'dispatcher', function () {

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

    $eventsManager->attach ( "dispatch:beforeException", function ( $event, $dispatcher, $exception ) {

        // Handle 404
        if ( $exception instanceof \Phalcon\Mvc\Dispatcher\Exception ) {
            $dispatcher->forward ( array (
                                       'controller' => 'CONTROLLER_NAME',
                                       'action'     => 'METHOD_NAME'
                                   ) );

            return FALSE;
        }

        // Handle others
        $dispatcher->forward ( array (
                                   'controller' => 'CONTROLLER_NAME',
                                   'action'     => 'METHOD_NAME'
                               ) );

        return FALSE;
    } );

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

    //Bind the EventsManager to the dispatcher
    $dispatcher->setEventsManager ( $eventsManager );

    return $dispatcher;

}, TRUE );