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

Hello! I'm having a problem (i hope i picked the right category) when i'm trying to use namespaces in my app. I have created a very basic app and i reproduce the issue there. I am new in phalcon and i'm working with 2.0.6.

This works :

(loader.php)

<?php

$loader = new \Phalcon\Loader();

$loader->registerDirs(array(APP_PATH . $config->application->controllersDir));

//$loader->registerNamespaces(array('Test\Controllers' => APP_PATH . $config->application->controllersDir));

$loader->register();

(IndexController.php)

<?php

//namespace Test\Controllers;

class IndexController extends \Phalcon\Mvc\Model {

    public function indexAction() {
    }
}

And this (what i'm trying to do) not :

(loader.php)

<?php

$loader = new \Phalcon\Loader();

//$loader->registerDirs(array(APP_PATH . $config->application->controllersDir));

$loader->registerNamespaces(array('Test\Controllers' => APP_PATH . $config->application->controllersDir));

$loader->register();

(IndexController.php)

<?php

namespace Test\Controllers;

class IndexController extends \Phalcon\Mvc\Model {

    public function indexAction() {
    }
}

Any ideas?



34.6k
Accepted
answer

You also have to setup the default namespace in the dispatcher: https://github.com/phalcon/forum/blob/master/app/config/services.php#L244-L252



2.9k

Yes i did find that out yesterday testing random solutions! It is not very clear in dodumentation i think. The way it is mentioned it makes someone think that it is only necessary if you have only one namespace for controllers which is not my case. The example is kept simple on purpose. Thanx anyway!