PhalconPHP - Unable to load controllers if they have names with a loader

Before I put in the space of my application (test application), everything worked fine. But after I started the namespace of the controllers, and that’s it, and loading the namespaces, like this:

    $loader = new Loader();
    $loader->registerNamespaces(
        array(
            'Application\Controllers' => 'Application/Controllers/'
        )
    )->register();

I get an error Exception: IndexController handler class cannot be loaded

The correct namespace has been entered:

namespace Application\Controllers;

use Phalcon\Mvc\Controller;

class IndexController extends Controller {

    public function indexAction() {
        echo "Hello World";
    }
}

img
(source: gyazo.com )

I managed to fix this by adding a default namespace to the router:

$router = new Router();
$router->setDefaultNamespace('Application\Controllers');

But this may cause me further problems because the namespace loader does not work.

What happened?

+4
source share
2 answers

, , .

. , - :

$controller = new Application\Controllers\IndexController(); .

, Application\Controllers. \IndexController, .

+6

, , Loader :

$loader = new Loader();
$loader->registerNamespaces(
    array(
        'Application' => 'Application'
    )
)->register();

, ? :

$loader = new Loader();
$loader->registerNamespaces(
    array(
        'Application' => '~/Application/'
    )
)->register();
+1

All Articles