0

我正在为我的 cakephp 项目添加登录/注销功能,当我登录或注销时,出现以下错误:

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

Stack Trace CORE\Cake\Controller\Component\AuthComponent.php line 376 → AuthComponent->constructAuthorize() CORE\Cake\Controller\Component\AuthComponent.php line 326 → AuthComponent->isAuthorized(array) [内部函数] → AuthComponent- >startup(UsersController) CORE\Cake\Utility\ObjectCollection.php 第 130 行 → call_user_func_array(array, array) [内部函数] → ObjectCollection->trigger(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 line 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 机器,或者调用我没有调用的函数。

4

1 回答 1

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

);
于 2012-08-10T18:45:55.553 回答