We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

IndexController handler class cannot be loaded when using new Router()

The following code of mine works:

router.php

<?php
$router = $di->getRouter();
$router->setDefaultNamespace('myphalcon\Controllers');
$router->removeExtraSlashes(true);

$router->add('/', [
    'controller' => 'Index',
    'action' => 'index'
])->setName('home');

$router->handle();

But as soon I remove the defaut router and use my own like this:

// $router = $di->getRouter();
$router = new \Phalcon\Mvc\Router(false);

I get the following error:

IndexController handler class cannot be loaded
#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('IndexController...', 2)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 C:\xampp\htdocs\phalcon\public\index.php(24): Phalcon\Mvc\Application->handle()
#3 {main}

My IndexController is very simple:

<?php

namespace myphalcon\Controllers;

class IndexController extends ControllerBase
{

    public function indexAction()
    {
        $this->tag->prependTitle('Home');
    }

}

You need to set this router in di.