2010-07-25 69 views
1

我有創造我自己的Zend_Auth_Adapter困難。我也在使用Doctrine 2。到目前爲止,我已經......下面創建自己的Zend_Auth_Adapter

代碼我收到錯誤

法「hasIdentity」不存在,並沒有被困在__call()

什麼錯?

use \Doctrine\ORM; 
class Application_Auth_Adapter implements Zend_Auth_Adapter_Interface { 
    private $username; 
    private $password; 

    function __construct($username, $password) { 
     $this->username = $username; 
     $this->password = $password; 
    } 

    function authenticate() { 
     $em = Zend_Registry::get('em'); 
     $query = $em->createQuery('select u from Application\Entities\User u WHERE u.name = :username') 
        ->setParameter('username', $this->username); 
     try { 
      $user = $query->getSingleResult(); 
      $salt = $user->salt; 
      $hashedPassword = hash_hmac('sha256', $this->password, $salt); 
      if ($hashedPassword == $user->password) { 
       // login success 
       return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $user); 
      } else { 
       // wrong password 
       return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, null); 
      } 
     } catch (NonUniqueResultException $e) { 
      // non unique result 
      return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null); 
     } catch (NoResultException $e) { 
      // no result found 
      return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, null); 
     } catch (Exception $e) { 
      // exception occured 
      return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null); 
     } 
    } 
} 

UPDATE

我注意到的問題來自ABT線Zend_Auth

if ($this->hasIdentity()) { 
    $this->clearIdentity(); 
} 

123,但略低於功能,authenticate(),其

public function hasIdentity() 

我發現了一些奇怪的是堆棧跟蹤

#0 [internal function]: Zend_Controller_Action->__call('hasIdentity', Array) 
#1 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Auth.php(123): AuthController->hasIdentity() 
#2 D:\Projects\Websites\php\ZendFramework\LearningZF\application\controllers\AuthController.php(23): Zend_Auth->authenticate(Object(Application_Auth_Adapter)) 
#3 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Controller\Action.php(513): AuthController->loginAction() 
#4 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('loginAction') 
#5 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#6 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() 
#7 D:\ResourceLibrary\Frameworks\ZendFramework\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 
#8 D:\Projects\Websites\php\ZendFramework\LearningZF\public\index.php(26): Zend_Application->run() 
#9 {main} 

看到AuthController-> hasIdentity()其試圖調用hasIdentity()AuthController

回答

1

我找到了原因!看到我的更新...堆棧跟蹤。我正在調用一個方法,就好像它是靜態的。會不會產生一個錯誤?反正...我會做

$ result = Zend_Auth :: getInstance() - > authenticate($ adapter);

0

尼斯適配器,不過我建議$用戶> getPassword來()和$用戶> getSalt()

+0

是不是我轉換所有的魔術方法'__get()__set()''來得到*()集*()'已經,謝謝補充。歡迎來到stackoverflow – 2010-12-26 07:10:37