In the CakePHP4 with the Authentication plugin we don’t get access to the logged in user details
Keen to keep code as simple as possible - how should this be handled? Do I need to pass the Identity in the custom finder? Is there some other preferred way?
I can’t say this is the correct way, so if not hopefully we’ll get corrected - but this is my approach.
In /src/AppController.php in public function beforeFilter(\Cake\Event\EventInterface $event) : -
It would be great if I didn’t need to pass $options from the “controller” in every find
@Zuluru I’m using Footprint to save the logged in user, from “_footprint” in $options, but not sure how that can be available beyond the events with save etc.
If that is the case, what I have done previously is just create a reusable Trait to add a protected method to obtain what I need via the Cake\Routing\Router Class in the Model.
The Footprint plugin injects itself into the various model event handlers, adding a “_footprint” (by default, it can be changed in the configuration) key into the options, with the identity as the value, which other listeners (e.g. beforeSave) can access. See the “Trait” section of the “Usage” part of the manual.