2009-10-19 10 views
0

저는 R00_Model_User 클래스가 있습니다.이 클래스는 충분히 흥미롭게도 사용자를 그대로 나타냅니다. $ result-> getIdentity()가이 클래스의 객체를 반환 할 수 있습니까? (아니면이 바보?)Zend_Auth가 클래스를 클래스로 반환 할 수 있습니까?

(개체를 복제에서 방지 R00_Model_User에 공장 방법이있다. 그것을 할 수 있다면 나는, Zend_Auth 대신 새로운 객체를 생성하는 그것을 사용하고 싶습니다) 하나에서

답변

2

두 가지 옵션 :

  • 는 서브 클래스 자신의 인증 어댑터를 쓰기 아웃 - 오브 - 박스 어댑터 이것은 당신이

    을 코딩 할 수

    class R00_Auth_Adapter extends Zend_Auth_Adapter_* 
    { 
        /** 
        * authenticate() - defined by Zend_Auth_Adapter_Interface. This method is called to 
        * attempt an authentication. Previous to this call, this adapter would have already 
        * been configured with all necessary information to successfully connect to a database 
        * table and attempt to find a record matching the provided identity. 
        * 
        * @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible 
        * @return Zend_Auth_Result 
        */ 
        public function authenticate() 
        { 
         $result = parent::authenticate(); 
         if ($result->isValid() { 
          return new Zend_Auth_Result(
           $result->getCode(), 
           R00_Model_User::load($result->getIdentity()), 
           $result->getMessages() 
          ); 
         } else { 
          return $result; 
         } 
        } 
    } 
    

    최고의 시나리오와 일치

    $adapter = new R00_Auth_Adapter(); 
    //... adapter initialisation (username, password, etc.) 
    $result = Zend_Auth::getInstance()->authenticate($adapter); 
    

    성공적으로 인증되면 사용자 개체가 자동으로 authentica에 저장됩니다. 스토리지 (기본적으로 세션).

  • 또는 저장된 사용자 ID

    $adapter = new Zend_Auth_Adapter_*(); 
    $result = $adapter->authenticate(); 
    if ($result->isValid()) { 
        $user = R00_Model_User::load($result->getIdentity()); 
        Zend_Auth::getInstance()->getStorage()->write($user); 
    } 
    
0

내 응용 프로그램의 getIdentity() 사용자 개체를 반환하고 꽤 잘 작동합니다. 당신의 팩토리 메소드를 사용하려면 다음과 같이 수행하십시오 getIdentity를 호출 할 때

$auth = Zend_Auth::getInstance(); 
$user = R00_Model_User::getInstance(...); 
$auth->getStorage()->write($user); 

다음(), 당신은 당신의 사용자 개체를해야합니다.

+0

흠을 업데이트하기 위해 로그인 액션을 사용합니다. ZF의 인증 코드를 사용하지 않고 직접 해보십시오. 나는 그것에 대해 생각할 것이다. 그러나 그것은 ZF-way처럼 보이지 않는다. –

+0

나는 당신이 무엇을 의미하는지 모른다? 나는 Zend_Auth를 사용하고 있지만 문자열 대신 객체를 저장하는 것으로하고있다. –

+0

기본적으로 Z_Auth는 사용자 이름을 저장합니다. 세션에만 암호를 저장하려는 경우 (DONT IT ITS UNSECURE)이 암호를 사용해야합니다. 그것은 그것을 할 수있는 유일한 방법입니다. 설명서 참조) 더보기. 확장하면 사용자 객체를 가져와 인증 객체에 전달할 수 있습니다. –

관련 문제