In beforeRender () just call
$this->set('userData', $this->Auth->user());
and set the data in the view and do your checks in the view.
To get the data in the layout, you must call the beforeRender()
method in the AppController.
Passing this through the session is not a good idea IMHO. This may not be the usual case, but at least I prefer to do something solid: if you use a session for this, your code will fail on a system that does not use a session (autat). In general, I am not a big fan of access to the session as a whole. Session for me is more like a data source.
source share