簡體   English   中英

如何將數據附加到Zend_Auth對象

[英]How to append data to Zend_Auth object

大家好日子,

我有以下代碼將存儲數據附加到Zend_Auth對象

    $auth        = Zend_Auth::getInstance();

    $dbAdapter   = Zend_Db_Table::getDefaultAdapter();

    $authAdapter = new Zend_Auth_Adapter_DbTable(
    $dbAdapter,
                'account', 
                'email', 
                'password',
                'delete_flag=0'
    );
    //MD5(?) AND  .. add this along with the prev where condn of delete flag...

    $authAdapter->setIdentity($loginDataArray['email'])
    ->setCredential($loginDataArray['password']);

    $result = $auth->authenticate($authAdapter); 
    var_dump($result);

    if ($result->isValid()) {

        $authStorage = $auth->getStorage();

        // the details you wan to store in the session
        $userDetails = array();         

        $userDetails['account_id']    = $account_id;
        $userDetails['email']      = $loginDataArray['email'];

        $authStorage->write($userDetails);
}

現在,如何在會話的后半部分添加更多數據。 我如何以后編輯相同的Zend_Auth對象。

身份驗證狀態存儲在已注冊的Auth Storage中。 默認情況下,這是Zend_Session。 你可以通過這個獲得會話

$namespace = new Zend_Session_Namespace('Zend_Auth');

然后做這樣的事情

$namespace->newname = "newvalue";

好吧,你不要'編輯'Zend_Auth身份。 你有不同的身份。 您可以通過Zend_Auth對象設置,讀取,寫入或清除存儲。

然而,我們中的許多人將這些相同的數據用於各種顯示目的,因此通常可以使用的解決方案是在存儲標識時將數據設置為不同的會話命名空間或注冊表項,或者只更新Zend_Auth創建的會話作為chandresh _ cool提示。

if ($result->isValid()) {

        $authStorage = $auth->getStorage();

        // the details you wan to store in the session
        $userDetails = array();         

        $userDetails['account_id']    = $account_id;
        $userDetails['email']      = $loginDataArray['email'];
        //add user data to registry
        $user = Zend_Registry::set('user', $userDetails);

        $authStorage->write($userDetails);
}

如果你真的想要做自己的事,你可以通過實現編寫自己的存儲適配器Zend_Auth_Storage_Interface或者您也可以通過實施寫自己的驗證適配器Zend_Auth_Adapter_Interface ,包括在適配器的存儲組件。

很多選擇,祝你好運。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM