i want to get user details who is logged on to my web site in zend framework .
Asked
Active
Viewed 1.2k times
5
-
1You will need to describe how your authentication system works for anyone to be able to answer this. Are you using Zend_Auth? – Jani Hartikainen May 01 '11 at 13:19
-
yes , i am using zed_Auth , i'm a new user , so can't explain in much details – Kanishka Panamaldeniya May 01 '11 at 13:21
-
Well if it's code you wrote you should be able to tell us what you are doing and what you have tried to solve your problem. Things like that help along questions quite nicely – Jani Hartikainen May 01 '11 at 13:30
2 Answers
14
You can get the data that's stored in Zend_Auth like this:
$identity = Zend_Auth::getInstance()->getIdentity();
The $identity
variable should now contain whatever data you stored into Zend_Auth when logging the user in.

Jani Hartikainen
- 42,745
- 10
- 68
- 86
-
I need the user in the layout in order to display the logged in user. How do I get the logged in user in ZF3 in the layout or view? – cwhisperer Jun 20 '18 at 13:33
2
this is part of a function that return usernme detail
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$username = $this->view->escape(ucfirst($user->username));
}
for another details u can use of $user->otherDetailName
if u save them when user login to site !

afsane
- 1,889
- 6
- 25
- 40
-
The value stored in the identity does not always contain an object. It depends on what was put there in the first place... Otherwise correct :) – Jani Hartikainen May 01 '11 at 13:31