Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-21-2008, 11:33 PM
dele454's Avatar
Member
 
Join Date: Jun 2008
Posts: 48
Default Auth->getIdentity()!

Am trying to retrieve the identity 'value' of the authenticated user

...
public function updateLastLogin() {

$login_data = $this->_getFormData();
$id = $this->_getAdminID($login_data);
$now = date("Y-m-d H:i:s");
$admins = new Admins();
$rowset = $admins->find($id)->current();
$rowset->LastLogin = $now;
$rowset->save();


}

protected function _getAdminID() {

$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$admins = new Admins();
$select = $admins->fetchRow($admins->select()->where('UserName = ?',$user));
return $select->AdminID;


...

}[/code]

Now i want to retrieve the id of the admin by getting the identity(getIdentity()) and then query my model (Admins) for the id of the admin for update.

Shouldnt getIndentity return the value for username e.g 'dele454' at the moment i cant echo the value stdClass error in order to see what the value the $user holds.

How can i ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-22-2008, 09:28 AM
dele454's Avatar
Member
 
Join Date: Jun 2008
Posts: 48
Default

Sorted!!

The getIdentity() function of the Auth class returns and associative array - an stdClass Object.

So in order for me to get the id from the authenticated identity. i simply used the follwing codes

Quote:
$obj = get_object_vars($user);
$keys = array_keys($obj);//print $obj[$keys[3]];
return $id = $obj[$keys[0]]; // outputs the admin id
funny enough i didnt need to instantiate my Admins Table class in order to get the id of the admin. getIdentity() returns the whole row of the admin identified from the db. - very powerful function!!!

so

Code:
...
$user = $auth->getIdentity();
print_r($user);
...
returns something like this:

Code:
stdClass Object ( [AdminID] => 1 [UserName] => dele454 [Password] => c2e952765241f5aa228c494042f7d5aa [FirstName] => Dele [SurName] => Agagu [Cell] => 0822926034 [Online] => 0 [RoleID] => 1 [LastLogin] => 2008-07-22 11:21:53 )

Last edited by dele454 : 07-22-2008 at 09:41 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-22-2008, 10:48 AM
dele454's Avatar
Member
 
Join Date: Jun 2008
Posts: 48
Default

With all the blabbings on my last post this single line of code does all that i mentioned.

Code:
$user = $auth->getIdentity();
$user->AdminID //get id of admin from db
SIMPLE!!! Makes sense because $user is an object representing the identified admin record

Last edited by dele454 : 07-22-2008 at 10:59 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:07 AM.