tags:

views:

268

answers:

2

In core.php I can define

Configure::write('Routing.admin', 'admin');

and /admin/controller/index will work.

but if I define both

Configure::write('Routing.admin', 'admin');
Configure::write('Routing.superuser', 'superuser');

and try to look at /superuser/blah/index/ instead of it saying the controller doesn't exist it says

Error: SuperuserController could not be found.

instead of saying

Error: BlahController could not be found.

When I first read the documentation I was under the impression I could run both routes, and not just one or the other. Is there something more I need to do?

+4  A: 

I believe they are working on this for CakePHP 1.3, but for now, we have to cheat to accomplish additional routing. This is the method I've used in the past.

// SuperUser Routing
Router::connect('/superuser/:controller',
    array('prefix' => 'superuser', 'superuser' => true));
Router::connect('/superuser/:controller/:action/*',
    array('prefix' => 'superuser', 'superuser' => true));

There were some issues generating URLs using the array('controller' => ...) method, but I haven't touched that project in a few months, so I can't remember all the caveats with it. This should at least give you a starting point though.

The CakePHP document explains this some. The relevant section starts about halfway in talking about multiple prefixes.

Jason
That works. I'll have to keep an eye out for those issues you mentioned.
Jack B Nimble
I think it had to do with explicitly needing to set 'prefix' => false or something like that when you were using the route and using an array for the URL.
Jason
A: 

If you're using Jason's trick, and having trouble with generating URLs using the array('controller' => ...) syntax, then put this in your appcontroller:

if (isset($this->params['prefix']) && $this->params['prefix'] == 'superuser') {      Configure::write('Routing.admin', 'superuser');
}

This forces the appcontroller to use the correct admin prefix, which in this case is "superuser".

Ben Hitchcock