cakePHP使用两个控制器进行路由

I have use a cakePHP framework. I have issue with the routing in cakephp.

I have two controller "Admins" and "Users".

I have write some methods for the "Admins" controller in "Users" controller. See below example.

class UsersController {
    public function admin_index() {
       my_code
    }
}

class AdminsController {
    My methods
}

As per cakephp routing rules if I want to use admin_index method from the admin controller than use below URL :

site_url/admin/users/index

I want to remove admin keyword from the above URL.

I have search out lots of on google but I have not got any proper solution.

Thanks in advance for helping me.

I found the solution.

User prefix in your Router connect

Router::connect('/:controller/:action/*', array('prefix' => 'admin', 'admin' => true, 'controller' => 'admins'));

if you want to add a condition on your parameters like (':action' is 'addUser' : In this example this router effects only when it's action is 'addUser') than use below code

Router::connect('/:controller/:action/*', array('prefix' => 'admin', 'admin' => true, 'controller' => 'admins'),
                                          array('action'=>'index|edit'));

If you need to use admin_index from AdminsController then your url should be site_url/admin/admins/index

Also check this this line in you core.php file:

https://github.com/cakephp/cakephp/blob/2.5/app/Config/core.php#L152

If you need to use site_url/admin/users/index for the admin_index method inside your AdminsController then I would prefer to disable the routes from core file and write the routes again.

Please read this too CakePHP - Routing Using 'admin_' Prefix. Might be helpfull