提问者:小点点

授权适配器


我添加登录/注销能力到我的cakephp项目,当我登录或退出我得到以下错误:

错误:找不到授权适配器“控制器”。错误:发生内部错误。

堆栈跟踪核心\Cake\Controller\Component\AuthComponent。php第376行→ AuthComponent-

这是我的AppController.php

class AppController extends Controller {
    public $components = array(
        'Session',
        'Auth'=>array(
            'loginRedirect'=> array('controller'=>'users', 'action'=>'index'),
            'logoutRedirect'=> array('controller'=>'users', 'action'=>'index'),
            'authError' =>"You can't access that page",
            'authorize'=> array('Controller)')
        )

    );
    //determines what logged in users have access to
    public function isAuthorized($user){
        return true;
    }
    //determines what non-logged in users have access to
    public function beforeFilter(){
        $this->Auth->allow('index','view');
        $this->set('logged_in', $this->Auth->loggedIn());
        $this->set('current_user', $this->Auth->user());
    }


}

这是我的UsersController.php

class UsersController extends AppController {
    public $name = 'Users';

    public function beforeFilter(){
        parent::beforeFilter();
        $this->Auth->allow('add');
    }

    public function login(){
        if($this->request->is('post')){
            if($this->Auth->login()){
                $this->redirect($this->Auth->redirect());

            }else{
                $this->Session->setFlash('Your username and/or password is incorrect');
            }
        }
    }

    public function logout(){
        $this->redirect($this->Auth->logoutRedirect());
    }

我注意到有几篇类似的文章也有相同的错误,但问题涉及到我在windows上的Linux机器,或者调用我没有调用的函数。


共1个答案

匿名用户

您在您的$组件['Auth']数组中犯了一个错误。您写了'Controller)'而不是'Controller'(错误消息告诉您)。以下是更正后的$组件

public $components = array(
    'Session',
    'Auth'=>array(
        'loginRedirect'=> array('controller'=>'users', 'action'=>'index'),
        'logoutRedirect'=> array('controller'=>'users', 'action'=>'index'),
        'authError' => "You can't access that page",
        'authorize'=> array('Controller')
    )

);