【问题标题】:Cakephp error: Authentication adapter "xmlRpc" was not foundCakephp 错误:未找到身份验证适配器“xmlRpc”
【发布时间】:2013-10-15 10:39:54
【问题描述】:

当我尝试实现自定义登录组件时,x 给我一个错误“未找到身份验证适配器“xmlRpc”。

在我的 AppController.php 我有以下

<?php

App::uses('Controller', 'Controller');

//Custom Auth
App::uses('xmlRpc', 'Controller/Component/Auth');

class AppController extends Controller {

    //Authentication component

    public $components = array(
        'Session',
        'DebugKit.Toolbar',
        'Auth' => array(
            'authenticate' => array(
                    'xmlRpc'
                )           
            )
        );

}

然后我的登录组件位于 /Controller/Component/Auth/xmlRpc.php

<?php

App::uses('BaseAuthenticate', 'Controller/Component/Auth');

class xmlRpc extends BaseAuthenticate {

    public function authenticate(CakeRequest $request, CakeResponse $response) {
        return true;
    }
}
?>

在我的用户控制器中,我有以下内容:

<?php
App::uses('AppController', 'Controller');

//Custom Auth
App::uses('xmlRpc', 'Controller/Component/Auth');

class UsersController extends AppController {

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

    public function login() {

        if ($this->request->is('post')) {

            if ($this->Auth->login()) {

                return $this->redirect($this->Auth->redirectUrl());
                // Prior to 2.3 use `return $this->redirect($this->Auth->redirect());`

            } else {

                $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
            }
        }
    }

}
?>

顺便说一下,在我的身份验证函数中,我总是返回 true 来进行测试。一旦我摆脱了这个错误,就会添加逻辑。请协助并放轻松,因为我是Cake n00b。如何获取 cake 以查看我的自定义身份验证适配器?

【问题讨论】:

    标签: php cakephp authentication


    【解决方案1】:

    我认为您的身份验证适配器的正确名称应该是 xmlRpcAuthenticate

    class xmlRpcAuthenticate extends BaseAuthenticate {
    

    【讨论】:

      【解决方案2】:

      遵循 CakePHP 的命名约定,类应该命名为XmlRpcAuthenticate,文件也是(当然扩展名为.php)。在App::uses() 调用和配置中使用不带Authenticate 的名称,即XmlRpc

      // This App::uses()  call is actually not necessary in the controller unless
      // your are actually trying to access the class directly
      App::uses('XmlRpc', 'Controller/Component/Auth');
      
      ...
      
      public $components = array(
          ...
      
          'Auth' => array(
              'authenticate' => array(
                   'XmlRpc'
              )           
          )
      );
      

      另见http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#creating-custom-authentication-objects

      【讨论】:

        【解决方案3】:

        只需将你的函数的首字母大写,我也是这样解决的。谢谢

        【讨论】:

          猜你喜欢
          • 2018-06-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-09-21
          • 1970-01-01
          • 2018-10-28
          • 1970-01-01
          相关资源
          最近更新 更多