russanto
russanto

Reputation: 21

Zend_Auth->getStorage->write() data object lost

i'm getting crazy with my authentication data.

When my in my app someone logs in, my authcontroller stores the user data in the Zend_Auth storage

class AuthController extends Zend_Controller_Action
{ ...
   public function loginAction()
   { ...
      $userMapper = new Application_Model_UsersMapper();
      $user = $userMapper->fetchById($adapter->getResultRowObject()->id);
      $this->auth->getStorage()->write($user);
   }
}

After this, I created a plugin to add user permitions (that are stored in the User object returned by the $userMapper) to my Acl System.

The problem is that when I call Zend_Auth->getInstance()->getIdentity(), I find only the username instead of the entire Object !

Upvotes: 1

Views: 2782

Answers (2)

russanto
russanto

Reputation: 21

I have solved my problem ! There was an error in mysql configuration. read() function, not finding anything in the Storage, returned username. Thank you for helping me.

Upvotes: 1

Stoyan Dimov
Stoyan Dimov

Reputation: 5549

This is because the Identity is actually the username (in your case). If you want to get the entire object you can get it like this:

$user = $this->auth->getStorage()->read();

Another thing to consider is that the default storage for Zend_Auth is a session so you might need to serialize the object if it is attached to some other resources like db etc.

Hope this helps :)

Upvotes: 0

Related Questions