Cakephp admin路由前缀在登录后没有重定向到正确的前缀


Cakephp admin routing prefix not redirect to the correct prefix after login

我有2个管理员角色(超级,admin),在第一次登录,一切工作正常,但注销和登录作为一个不同的管理员后,它重定向到超级前缀。

这是我的应用控制器:

class AppController extends Controller {
public $helpers = array('Js', 'Session');
public $components = array(
    'Session',
    'RequestHandler',
    'DebugKit.Toolbar',
    'Auth' => array(
        'autoRedirect' => false,
        'loginAction' => array(
            'admin' => false,
            'super' => false,
            'controller' => 'users',
            'action' => 'login'
        ),
        'loginRedirect' => array(
            'controller' => 'users',
            'action' => 'dashboard',
            'admin'=> true,
            'super'=> true
        ),
        'logoutRedirect' => array(
            'admin' => false,
            'super' => false,
            'controller' => 'users',
            'action' => 'login'
        ),
        'authError' => 'Please login to continue.',
        'flash' => array('element' => 'flash/default', 'key' => 'auth', 'params' => array('class' => 'error', 'title' => 'Authentication Error')),
        'authorize' => 'Controller',
        'authenticate' => array(
            'Form' => array(
                'userModel' => 'User',
                'fields' => array(
                    'username' => 'email'
                    ),
            )
        ),
    )
);
public function isAuthorized($user) {
    # Accept if Admin
    if($user['admin']){
        return true;
    }
    # Check if current prefix is admin or physician and authenticate user
    if(isset($this->request->prefix)) {
        switch ($this->request->prefix) {
            case 'super':
                if(!$user['super']){
                    $this->Auth->authError = 'Sorry, you do not have permission to access the Manager''s area';
                }
                return $user['super'];
                break;
             case 'admin':
                if(!$user['admin']){
                    $this->Auth->authError = 'Sorry, you do not have permission to access the Administrators''s area';
                }else{
                    $this->layout = 'admin_layout';
                }
                return $user['admin'];
                break;
        }
    }else{
        $this->layout = 'super_layout';
        return true;
    }
    $this->Auth->authError = 'Sorry, you do not have permission to access the Admin area';
    return false;
}
public function beforefilter(){
    $this->appSettings = Configure::read('appSettings');
    $this->set('appSettings',  Configure::read('appSettings'));
    if (!$this->Auth->loggedIn()) {
        $this->Auth->authError = false;
    }
     if(isset($this->request->prefix)) {
        switch ($this->request->prefix) {
            case 'admin':
                $this->layout = 'admin_layout';
                $admin = true;
                break;
            case 'super':
                $this->layout = 'super_layout';
                $super = true;
                break;
        }
    }
}

property AuthComponent::$loginRedirect

用户登录后应该重定向到控制器动作的URL(定义为字符串或数组)。如果用户有Auth,这个值将被忽略。在会话中重定向值

如果您尝试访问domain.com/super/并尝试以管理员身份登录,cake将忽略$loginRedirect属性,在您登录后,它将尝试将您重定向到domain.com/super/,这是您最初尝试访问的链接