Get the current user in CakePHP4

This example shows you how to obtain user information from the session.

Note: Any changes made to a user while they are logged in, are not refreshed until user logs out, so this should be taken into consideration when thinking about features like instantly locking someone out.

$myUser = $this->request->getAttribute('identity');

Now you have a $myUser variable, and can get the corresponding fields:

$myUser['id']

 

Share this Post