CakePHP:为admin插件创建全局路由

So I started making the admin panel of our site as a plugin. And I'm able to redirect every request like domain.com/admin or domain.com/admin/users or domain.com/admin/pages/edit/5 - to the appropriate controller and action from the admin plugin. Like this one:

 Router::connect('/admin', array('plugin' => 'admin', 'controller' => 'index', 'action' => 'index'));
 Router::connect('/admin/users/list', array('plugin' => 'admin', 'controller' => 'users', 'action' => 'list'));

But this means I will have to write separate route for almost each URL ??? or actually - for each action ... So - is there a way to set it globally? ...

For example:

 Router::connect('/admin/users/*', array('plugin' => 'admin', 'controller' => 'users'));

Or even better:

 Router::connect('/admin/*', array('plugin' => 'admin'));

Cause the last two examples didn't work at all ...

EDIT: the CakePHP version is the latest at the moment - 2.4.1.

Normally you shouldn't have to create such routes for plugins, the basic mapping works out of the box, ie in case your plugin is named admin, then /admin/users/list will automatically map to plugin admin, controller users, action list.

An exception is your /admin route, by default this would look for index on AdminController. So for mapping to index on IndexController you'll need a custom route like the one in your question:

Router::connect('/admin', array('plugin' => 'admin', 'controller' => 'index', 'action' => 'index'));

Apart from this it should work as is in case you don't have any other preceding rules that will override the default behaviour, something like Router::connect('/*', ...) for example. In case there are such rules and you cannot change them, then this is how you could connect the basic routes of your plugin:

Router::connect('/admin/:controller/:action/*', array('plugin' => 'admin'));
Router::connect('/admin/:controller/*', array('plugin' => 'admin', 'action' => 'index'));
Router::connect('/admin/*', array('plugin' => 'admin', 'controller' => 'index', 'action' => 'index'));

Note that this needs to be placed before the other routes that override the default behaviour!

See also http://book.cakephp.org/2.0/en/development/routing.html

On a side note, list as an action name will probably not work, this should throw a parser error as list is a reserved keyword. So you in case this isn't just an example you'll need an extra route for that if you want to use /list as the action name in the URL.