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.

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?



33.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



1.3k

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!