You can set a view variable in AppControler:
public function beforeRender() {
$this->set('auth', $this->Auth->user());
}
and use it in the view:
if ($auth) {
echo $auth['username'];
}
On Monday, September 15, 2014 6:53:32 PM UTC+2, Dave Edwards wrote:
>
> In CakePHP 3.x what is the correct way to establish whether the user is
> logged in via Auth in a view/template?
>
> I found this https://github.com/cakephp/cakephp/issues/3929
> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fcakephp%2Fcakephp%2Fissues%2F3929&sa=D&sntz=1&usg=AFQjCNGHXaJlwIdSvjin9GJCB38XzvsWAw>
>
> which suggests that methods available in 2.x have been removed?
>
> Do I need to check in each and every controller and set something for the
> view?
>
> Can an example be provided please?
>
> Dave
>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.