dongping4901 2013-10-08 13:21
浏览 25
已采纳

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

x gives me an error "Authentication adapter "xmlRpc" was not found" when I try implement a custom login component.

In my AppController.php I have the following

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

}

Then I have my login compononent located in /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;
    }
}
?>

In my users controller I have the following:

<?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');
            }
        }
    }

}
?>

By the way in my authenticate function I always return true just for testing. Will add logic once I get rid of this error. Please assist and take it easy on me because im a Cake n00b. How to I get cake to see my custom authentication adapter?

  • 写回答

3条回答 默认 最新

  • doudao1369 2013-10-08 13:28
    关注

    Follow the CakePHP naming conventions, the class should be named XmlRpcAuthenticate, the file too (with .php extension of course). In the App::uses() call and in the configuration use the name without Authenticate, ie 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'
            )           
        )
    );
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料