5

i want to get user details who is logged on to my web site in zend framework .

Rob
  • 415,655
  • 72
  • 787
  • 1,044
Kanishka Panamaldeniya
  • 17,302
  • 31
  • 123
  • 193

2 Answers2

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