I am in the process of customizing the file
app_controller.php
, I have the following:
beforeFilter () function {$ User = $ this- & gt; Authorization-> the user (); If ($ user! = Null) {$ this-> Session-> Type ('user_name', $ user ['user'] ['username']); }}
and in default.ctp
, I have:
$ user = $ this-> Session-> gt; Read ('Auth.User'); If (! Blank ($ user)) {echo 'hello,' $ user ['user_name']; }
However, it seems that the value $ user_name
is not being set anywhere.
What am I doing wrong? Is this a better way to accomplish this?
Update: I have modified it as described in the answer, but it still does not work. I get an error:
undefined index: user_name [APP / view / layout / default.button, line21]
< Div class = "post-text" itemprop = "text">
You can use session allper directly in view / layout
$ user = $ this- & gt; Session-> Read ('Auth.User'); If (! Blank ($ user)) {echo 'hi', $ user ['user_name']; }
Comments
Post a Comment