【问题标题】:Authorization adapter "Controller)" was not found. in cakephp未找到授权适配器“Controller)”。在 cakephp 中
【发布时间】:2012-08-07 21:12:51
【问题描述】:

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

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

堆栈跟踪 CORE\Cake\Controller\Component\AuthComponent.php 第 376 行 → AuthComponent->constructAuthorize() CORE\Cake\Controller\Component\AuthComponent.php 第 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 第 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 机器,或者调用我没有调用的函数。

【问题讨论】:

    标签: apache cakephp


    【解决方案1】:

    您在 $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')
        )
    
    );
    

    【讨论】:

    • 不要忘记您的 Cake 2.x 案例,您必须完全相同。这是我的错误,这个答案对我有帮助。嘿嘿嘿……
    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2013-05-31
    • 2013-10-15
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多