未找到授权适配器“Controller”。在cakephp

时间:2012-08-10 14:32:10

标签: apache cakephp

我正在将cake / logout功能添加到我的cakephp项目中,当我登录或退出时出现以下错误:

错误: 未找到授权适配器“Controller”。 错误:发生内部错误。

堆栈跟踪 CORE \ Cake \ Controller \ Component \ AuthComponent.php第376行→AuthComponent-> constructAuthorize() CORE \ Cake \ Controller \ Component \ AuthComponent.php第326行→AuthComponent-> isAuthorized(数组) [内部功能]→AuthComponent->启动(UsersController) CORE \ Cake \ Utility \ ObjectCollection.php第130行→call_user_func_array(数组,数组) [内部功能]→ObjectCollection->触发器(CakeEvent) CORE \ Cake \ Event \ CakeEventManager.php第246行→call_user_func(array,CakeEvent) CORE \ Cake \ Controller \ Controller.php第671行→CakeEventManager-> dispatch(CakeEvent) CORE \ Cake \ Routing \ Dispatcher.php第183行→Controller-> startupProcess() CORE \ Cake \ Routing \ Dispatcher.php第161行→Dispatcher-> _invoke(UsersController,CakeRequest,CakeResponse) APP \ webroot \ index.php第92行→Dispatcher-> dispatch(CakeRequest,CakeResponse)

这是我的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 个答案:

答案 0 :(得分:4)

你在$components['Auth']数组中犯了一个错误。您编写了'Controller)'而不是'Controller'(错误消息告诉您)。这是更正的$components

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')
    )

);