繁体   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