简体   繁体   English

CakePHP路由前缀登录

[英]CakePHP Route prefix logins

I have several different roles of users for a system that include 'Admins, Students, Moderators' 对于系统,我有几种不同的用户角色,包括“管理员,学生,主持人”

But for the admins I want to have a unique login page so I have added: 但是对于管理员,我想拥有一个独特的登录页面,因此我添加了:

admin_login() and admin_logout() to my UsersController admin_login()admin_logout()到我的UsersController

But how would I send a user to the correct method if they tried to access say an admin area such as admin_index for my posts eg /admin/posts they would be taken to /admin/login 但是,如果用户尝试访问说我的帖子(例如/admin/posts的管理员区域(例如admin_index ,我将如何将其发送到正确的方法,他们将被带到/admin/login

I have thought about using something like: 我已经考虑过使用类似的东西:

if (isset($this->params['admin'])) {
            //
        }

BUT how would I tell it to use the admin login and logout methods over the default login? 但是我如何告诉它在默认登录名上使用admin登录和注销方法?

Thanks 谢谢

Inside of your if, you would modify the default login action 在if中,您将修改默认登录操作

$this->Auth->loginAction = array(
   'controller'=>'users',
   'action'=>'login',
   'prefix'=>'admin',
   'admin'=>true
);

This adds the prefix to the login redirect. 这会将前缀添加到登录重定向中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM