Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Undefined class constant 'EXCEPTION_HANDLER_NOT_FOUND'

<?php
use Phalcon\Events\Event;
use Phalcon\Dispatcher;
use Phalcon\Mvc\Dispatcher\Exception as DispatcherException;

$evManager->attach(
            'dispatch:beforeException',
            function($event, $dispatcher, $exception)
            {   
                switch ($exception->getCode()) {
                    case MvcDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                    case MvcDispatcher::EXCEPTION_ACTION_NOT_FOUND:
                        $MvcDispatcher->forward(
                            array(
                                'namespace' => 'Controllers',
                                'controller' => 'No',
                                'action'     => 'index',
                            )
                        );
                        return false;
                }
            }
        );

Get error Undefined class constant 'EXCEPTION_HANDLER_NOT_FOUND'



255
Accepted
answer

If none of the routes, specified in the router, match, you can define a 404 controller/action by using the notFound method.

<?php

$router->notFound(
    [
        'controller' => 'index',
        'action'     => 'fourOhFour',
    ]
);

NOTE: This will only work if the router was created without default routes: $router = Phalcon\Mvc\Router(false);