2013-10-08 42 views
0

x當我嘗試實現自定義登錄組件時,x給出錯誤「身份驗證適配器」xmlRpc「未找到」。Cakephp錯誤:未找到身份驗證適配器「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; 
    } 
} 
?> 

在我的用戶控制我自己的登錄compononent有以下幾點:

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

} 
?> 

順便說一下,在我的身份驗證功能,我總是返回真正的供測試用。一旦我擺脫了這個錯誤,會添加邏輯。請協助並輕鬆放輕鬆,因爲我的蛋糕n00b。如何獲取蛋糕以查看我的自定義身份驗證適配器?

回答

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

+0

謝謝。這工作! –

0

我覺得你的身份驗證適配器正確的名稱應該是xmlRpcAuthenticate

class xmlRpcAuthenticate extends BaseAuthenticate { 
0

只是讓你的函數的第一個字母大寫,我也解決了它這樣..謝謝