简体   繁体   English

如何将数据附加到Zend_Auth对象

[英]How to append data to Zend_Auth object

Good Day to All, 大家好日子,

I have the following code which appends stores 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);
}

Now, How do i append any more data in the later part of the session. 现在,如何在会话的后半部分添加更多数据。 How do i edit the same Zend_Auth object later. 我如何以后编辑相同的Zend_Auth对象。

Authentication state is stored in the registered Auth Storage. 身份验证状态存储在已注册的Auth Storage中。 By default this is Zend_Session. 默认情况下,这是Zend_Session。 You can get session by this 你可以通过这个获得会话

$namespace = new Zend_Session_Namespace('Zend_Auth');

then do somthing like this 然后做这样的事情

$namespace->newname = "newvalue";

ok, you don't 'edit' Zend_Auth Identity. 好吧,你不要'编辑'Zend_Auth身份。 You either have an identity or not. 你有不同的身份。 You can set, read, write or clear storage through the Zend_Auth object. 您可以通过Zend_Auth对象设置,读取,写入或清除存储。

However many of us use this same data for various display purposes so a solution that often works is to set the data to a different session namespace or a registry key when the identity is being stored or just update the session that Zend_Auth creates as chandresh _ cool suggests. 然而,我们中的许多人将这些相同的数据用于各种显示目的,因此通常可以使用的解决方案是在存储标识时将数据设置为不同的会话命名空间或注册表项,或者只更新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);
}

if you really want to do your own thing you can write your own storage adapter by implementing Zend_Auth_Storage_Interface or you can write your own Auth adapter by implementing Zend_Auth_Adapter_Interface and include the storage component in the adapter. 如果你真的想要做自己的事,你可以通过实现编写自己的存储适配器Zend_Auth_Storage_Interface或者您也可以通过实施写自己的验证适配器Zend_Auth_Adapter_Interface ,包括在适配器的存储组件。

Lots of choices, good luck. 很多选择,祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM