Cakephp错误:找不到身份验证适配器“xmlRpc”

时间:2013-10-08 13:21:18

标签: php cakephp authentication

当我尝试实现自定义登录组件时,

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进行测试。一旦我摆脱了这个错误,就会添加逻辑。请帮助我,让我轻松一点,因为我是一个蛋糕n00b。如何获得蛋糕以查看我的自定义身份验证适配器?

3 个答案:

答案 0 :(得分:1)

遵循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

答案 1 :(得分:0)

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

class xmlRpcAuthenticate extends BaseAuthenticate {

答案 2 :(得分:0)

只要你的函数的首字母大写,我也这样解决了..谢谢