cakephp why can't I have an admin route and a superuser route?
In core.php I can d开发者_如何学Pythonefine
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?
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.
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".
精彩评论