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.

$router->notFound doesn't work

Why it doesn't work?

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


Application send exception: PublicfdgdfggdfController handler class cannot be loaded



This is only work if the action is not found, try this:

//Registering a dispatcher
        $di->set('dispatcher', function () {
            //Create/Get an EventManager
            $eventsManager = new \Phalcon\Events\Manager();
            //Attach a listener
            $eventsManager->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:
                                'controller' => 'index',
                                'action' => 'notFound'

                            return false;

            $dispatcher = new \Phalcon\Mvc\Dispatcher();
            //Set default namespace to backend module
            //Bind the EventsManager to the dispatcher

            return $dispatcher;

edited Jul '14

So sad, but it's working. Thank you.