Search code examples
phpzend-frameworkzend-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

    $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.


Solution

  • Authentication state is stored in the registered Auth Storage. By default this is Zend_Session. You can get session by this

    $namespace = new Zend_Session_Namespace('Zend_Auth');
    

    then do somthing like this

    $namespace->newname = "newvalue";