Andrew
Andrew

Reputation: 239197

Zend Framework: How best to go about retrieving the first name of an authenticated user?

I can get the username by doing this:

public function indexAction()
{
    $this->view->username = Zend_Auth::getInstance()->getIdentity();
}

"username" is the column in the table that validates the identity. "firstname" is also a column in that table. Does Zend_Auth only store the username? Or is there a way to access other columns from the user's row in the table?

Upvotes: 1

Views: 239

Answers (1)

markus
markus

Reputation: 40685

So you're using a DbTable adapter, right. And are you retrieving the table row after authentication like so:

$authAdapter->getResultRowObject()

Then yes, the whole user-row is available. Just try!

From the manual:

In addition to the availability of the getIdentity() method upon the authentication result object, Zend_Auth_Adapter_DbTable also supports retrieving the table row upon authentication success:

// Print the identity
echo $result->getIdentity() . "\n\n";

// Print the result row
print_r($authAdapter->getResultRowObject());

/* Output:
my_username

Array
(
    [id] => 1
    [username] => my_username
    [password] => my_password
    [real_name] => My Real Name
)
*/

Or see for yourself!

Upvotes: 3

Related Questions