# Displaying logged-in user in header

**URL:** <https://discourse.cakephp.org/t/displaying-logged-in-user-in-header/7666>\
**Category:** Need Help\
**Created:** [April 16, 2020, 9:57am UTC](https://discourse.cakephp.org/t/displaying-logged-in-user-in-header/7666 "2020-04-16T09:57:44Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![HypJ3U50N](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/hypj3u50n/32/1803_2.png) [@HypJ3U50N](https://discourse.cakephp.org/u/HypJ3U50N)\
**Post date:** [April 21, 2020, 9:03am UTC](https://discourse.cakephp.org/t/displaying-logged-in-user-in-header/7666/18 "2020-04-21T09:03:10Z")

</div>

I have no knowledge about ternary operator performance, but your solution was indeed what I meant by using CakePHP methodology. I stored this code in a variable such that the code doesn’t need to be inside the html.

However, I don’t understand why this works and does not result in the same error of `Record not found in table "users" with primary key [NULL]` since I thought this was due to the view($id=null) in UserController.php.

So I see from this that the current user and the Users functions can be accessed through controller (whereas $user is unknown). I made a [new topic](https://discourse.cakephp.org/t/accessing-controller-authorization-through-template-view/7692) since I can’t apply similar access in the index View of Articles.

---

_[View the full topic](https://discourse.cakephp.org/t/displaying-logged-in-user-in-header/7666)._
