# Getting user information in nav-top bar

**URL:** <https://discourse.cakephp.org/t/getting-user-information-in-nav-top-bar/2891>\
**Category:** Need Help\
**Created:** [July 16, 2017, 8:09pm UTC](https://discourse.cakephp.org/t/getting-user-information-in-nav-top-bar/2891 "2017-07-16T20:09:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpforte](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jpforte/32/716_2.png) [@jpforte](https://discourse.cakephp.org/u/jpforte)\
**Post date:** [July 16, 2017, 8:09pm UTC](https://discourse.cakephp.org/t/getting-user-information-in-nav-top-bar/2891/1 "2017-07-16T20:09:13Z")

</div>

Hi, Newbie here, but programming for 35 years.

I have loaded the cakedc/users plugin and he admin LTE theme. I have users that login. I want the current user name and information to appear in the top nav, not the hard coded alex user.

I have copied the template to src/Templates/Element/nav-top.ctp I can edit the template and changes take effect. I tried $this-\>User-\>last\_name but it produces no output. just to test that I have the correct format $this-\>User-\>logout() produces the logout link. How do I get individual fields?

---

<div class="post-metadata">

**Author:** ![Andrej](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/andrej/32/446_2.png) [@Andrej](https://discourse.cakephp.org/u/Andrej)\
**Post date:** [July 17, 2017, 10:35am UTC](https://discourse.cakephp.org/t/getting-user-information-in-nav-top-bar/2891/2 "2017-07-17T10:35:52Z")

</div>

You have to pass user info to view layer from your AppController, e.g.

```auto
public function beforeRender(Event $event)
{
    parent::beforeFilter($event);

    $this->set('userInfo', $this->Auth->user())
}

```

Then you can use $userInfo var in your templates.

---

<div class="post-metadata">

**Author:** ![jpforte](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jpforte/32/716_2.png) [@jpforte](https://discourse.cakephp.org/u/jpforte)\
**Post date:** [July 17, 2017, 3:17pm UTC](https://discourse.cakephp.org/t/getting-user-information-in-nav-top-bar/2891/3 "2017-07-17T15:17:40Z")

</div>

Thanks, Sort of works but not really.

in src/Controller/AppContoller.php I added what is past the JPF comment

> public function beforeRender(Event $event)  
> {  
> if (!array\_key\_exists(‘\_serialize’, $this-\>viewVars) &&  
> in\_array($this-\>response-\>type(), [‘application/json’, ‘application/xml’])  
> ) {  
> $this-\>set(‘\_serialize’, true);  
> }  
> $this-\>set(‘theme’, Configure::read(‘Theme’));  
> // JPF July 17 2017  
> parent::beforeFilter($event);  
> $this-\>set(‘userInfo’, $this-\>Auth-\>user());  
> }

In src/Template/Element/nav-top.ctp I used

> \<?php echo $userinfo["username"]; ?\>

The website barfed this out

> Notice (8): Undefined variable: userinfo [APP/Template/Element/nav-top.ctp, line 112]

Despite the variable being defined in the debugging panel.

---

<div class="post-metadata">

**Author:** ![Andrej](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/andrej/32/446_2.png) [@Andrej](https://discourse.cakephp.org/u/Andrej)\
**Post date:** [July 17, 2017, 3:31pm UTC](https://discourse.cakephp.org/t/getting-user-information-in-nav-top-bar/2891/4 "2017-07-17T15:31:07Z")

</div>

`userinfo` vs `userInfo`

---

<div class="post-metadata">

**Author:** ![jpforte](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jpforte/32/716_2.png) [@jpforte](https://discourse.cakephp.org/u/jpforte)\
**Post date:** [July 18, 2017, 11:41am UTC](https://discourse.cakephp.org/t/getting-user-information-in-nav-top-bar/2891/5 "2017-07-18T11:41:52Z")

</div>

Oh, egg on face. Spelling counts. Thanks for your patience.
