1

I'm new at the latest cakephp versions and hadn't used the Authentication Component until now. I'm trying to validate a user being an admin but can't find how to get the user id to get it, nor how to get the identifier. $this->Authentication->getIdentifier() throws an error that the identifier does not exist.

In general I'm trying to do a little cms to learn new framework usage and such. Haven't used it since 2.x

SrQ
  • 106
  • 7

1 Answers1

4

It's $this->Authentication->getIdentity()->getIdentifier() to get the id. You can also use the get()-method to get other fields, for example $this->Authentication->getIdentity()->get('username') returns the username.

ndru
  • 83
  • 1
  • 10
  • It should be noted this is how you access the logged in user in a Controller. In a View you need to use `$this->getRequest()->getAttribute('identity')->getIdentifier()` or `$this->getRequest()->getAttribute('identity')->get('username')` – Naidim Apr 27 '23 at 18:57