Micro notFound

I've set up a Micro app to function as a CMS. So there will be potentially infinite possible routes, that I want to all direct to my Index handler.

I've set up my index.php file like so:

$App = new \Phalcon\Mvc\Micro;
$App->setDI($DI);
$App->notFound(function(){
    $Index = new \Handler\Index();
    $Index->handle();
});

$App->handle();

When I go to www.site.com/dev/, which is the homepage, everything works fine. handle() gets called. However, when I go to a sub-page like www.site.com/dev/blah, I get Fatal error: Uncaught Phalcon\Mvc\Micro\Exception: Matched route doesn't have an associated handler. Well I haven't set up any routes, so everything should be going to the notFound handler.

What am I missing?

edited 4d ago
$app->notFound(
    function () use ($app) {
        $app->response->setStatusCode(404);
        $message = 'This is crazy, but this page was not found!';
        $app->response->setContent($message);
        !$app->response->isSent() && $app->response->send();
        exit;
    }
);

https://docs.phalconphp.com/en/latest/application-micro#routing-handlers-not-found

I think there is some predefined routes. You can clear them:

$di->get('router')->clear();