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

Handler class cannot be loaded

Hi guys,

I've been trying out Phalcon 3 and I've made dev env with https://phalcon-compose.readme.io/

But I keep geting this error message in app.

Every time this code:

echo (new Application($di))->handle()->getContent();

Produces this or similar error:

MyMapApp\Controllers\IndexController handler class cannot be loaded
#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('MyMapApp\\Contro...', 2)
#1 [internal function]: Phalcon\Dispatcher->_dispatch()
#2 [internal function]: Phalcon\Dispatcher->dispatch()
#3 /project/public/index.php(19): Phalcon\Mvc\Application->handle()
#4 {main}

My loader looks like this:

$loader = new Loader();
$loader->registerNamespaces([
 'MyMapApp\Models'      => $config->application->modelsDir,
  'MyMapApp\Controllers' => $config->application->controllersDir
])->register();

require_once BASE_PATH . '/vendor/autoload.php';

Router & dispatcher like this:

$di->set('dispatcher', function () {
  $dispatcher = new Dispatcher();
  $dispatcher->setDefaultNamespace('MyMapApp\\Controllers');
  return $dispatcher;
});

$di->set('router', function () {
  $router = new Phalcon\Mvc\Router();

  $router->setDefaultController('index')->setDefaultAction('index');
  $router->removeExtraSlashes(true);

  $router->add('/homepage', ['controller' => 'Homepage', 'action' => 'index']);
  $router->add('/login', ['controller' => 'Login', 'action' => 'index']);

  return $router;
});

Does anyone have an idea what could have gone wrong so I get this error and how to fix it?

P.S.

Even if I create default IndexController that looks like this:

class IndexController extends Controller
{
    public function indexAction()
    {
        return "<h1>Homepages!</h1>";
    }
}

I also get similar error:

Homepages!"; } }MyMapApp\Controllers\IndexController handler class cannot be loaded
#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('MyMapApp\\Contro...', 2)
#1 [internal function]: Phalcon\Dispatcher->_dispatch()
#2 [internal function]: Phalcon\Dispatcher->dispatch()
#3 /project/public/index.php(17): Phalcon\Mvc\Application->handle()
#4 {main}


85.5k
edited Dec '16

check if this variable coresponds to correct folder of controllers $config->application->controllersDir.

make sure you didnt misspelled a controller name / filename with a cirillyc or so letter ( by accident )

try using absolute paths to make sure path is correct.

If you dont know it already - the problem is with the loader for sure, you can check docs and read them carefully to make sure you understand how loaders works. ( namespace = folder name, class name = file name.php )

Tnx, but I've already triple checked names and tried absolute paths, they are correctly configured because it renders some output like "Homepages!" in previous example.

I guess I'll have to dive into loaders.

edited Dec '16

And you sure that direcotry name is Controllers and file name is IndexController.php ?

Handler class cannot be loaded means taht this class can't be loaded - in 99,9% by autload - meaning that you have for 100% wrong paths(provided or wrong in system - wrong case)

Yeah I'm sure. But it doesn't matter anymore because I pulled sample project and bareboned it. Now everything works fine regarding distpatching and routing, altought I guess I'll never know what was the real case.

Tnx for help guys.

edited Dec '16

I wrote - wrong paths(including wrong case of folder names) for 99%.

Yeah I'm sure. But it doesn't matter anymore because I pulled sample project and bareboned it. Now everything works fine regarding distpatching and routing, altought I guess I'll never know what was the real case.

Tnx for help guys.

you could better explain how you solved the problem. I have the same and I could not give it a solution ty