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

Router does not recognize the namespace

Code:

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


98.9k

Maybe the route is not being matched



3.7k

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



2.2k

You can test your routes: https://docs.phalcon.io/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?



3.7k

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

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

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



2.2k

I can't reproduce it.

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

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



2.2k
edited Jan '15

https://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?



3.7k
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