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.

Router does not recognize the namespace

Code:

$router->add('/admin/:controller/:action/:params', array(
    'namespace' => 'App\Controllers\Admin',
    'controller' => 1,
    'action' => 2,
    'params' => 3,
));


83.4k

Maybe the route is not being matched



2.2k

It works on my computer but the web server does not work. php 5.5



1.6k

You can test your routes: http://docs.phalconphp.com/en/latest/reference/routing.html#testing-your-routes

And do you use the exact same verion of Phalcon both on your computer and on your web server?



2.2k

I did a test does not work https://github.com/phalcon/mvc/tree/master/simple-subcontrollers shows me the message:

MyApp\Controllers\Admin\UsersController handler class cannot be loaded

http://rengifo.koding.io/users (ok)

http://rengifo.koding.io/admin/users (fail)



1.6k

I can't reproduce it.

http://localhost:8000/users -> Users (no admin)

http://localhost:8000/admin/users -> Users (admin)



1.6k
edited Jan '15

http://rengifo.koding.io/admin/users says:

Dispatcher has detected a cyclic routing causing stability problems
#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('Dispatcher has ...', 1)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 /home/rengifo/Web/public/index.php(33): Phalcon\Mvc\Application->handle()
#3 {main}

It seems you have wrong routing config?



2.2k
Accepted
answer
edited May '15

This line was my headache for several hours

$loader = new \Phalcon\Loader();

/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerNamespaces(array(
    'MyApp\Controllers' => __DIR__ . '/../controllers/',
    'MyApp\Controllers\Admin' => __DIR__ . '/../controllers/admin' //<---- this line!
))->register();

but at last I found solution how good it feels to learn a little more Phalcon