Displaying logged-in user in header

Oh, I see the problem! You’re trying to reference the $identity variable in a function inside AppView. That’s not so much “a view” as “the class the builds the view”. It works like any other class and function, so you’re trying to reference a variable that wasn’t declared, with the expected result. Where $identity will be available to you is in places like src/Template/Users/view.ctp or, since you want it everywhere, src/Template/Layout/default.ctp. Those files are executed by the View class, in a context that’s been specially set up with all the variables that you’ve set.

1 Like