08-06-2023, 04:25 PM
I wanna gather the latest information of a user from the User Model and store it in the session.
so i am doing this
// Before Render
function beforeRender() {
if($this->Session->check('Auth.User')) {
$this->User->recursive = -1;
$currentUser = $this->User->read(null, $this->Session->read('Auth.User.id'));
$this->set(compact('currentUser'));
}
}
It works fine until am in the User model.
When i go to the pages it gives me an error because User->read doesnt work as that model is not attached there.
Whats the best solution for ?
1. I want the latest information of the Loggedin User on every page of the site.
2. Latest and not Auth.User from the session because - when i edit the profile content like name or photo. it still references to the old data that was stored when user had logged on.
3. It has to be displayed on every page like the Stackoverflow User info at the top
![alt text][1]
[1]:
Which is the best way to do it ?
so i am doing this
// Before Render
function beforeRender() {
if($this->Session->check('Auth.User')) {
$this->User->recursive = -1;
$currentUser = $this->User->read(null, $this->Session->read('Auth.User.id'));
$this->set(compact('currentUser'));
}
}
It works fine until am in the User model.
When i go to the pages it gives me an error because User->read doesnt work as that model is not attached there.
Whats the best solution for ?
1. I want the latest information of the Loggedin User on every page of the site.
2. Latest and not Auth.User from the session because - when i edit the profile content like name or photo. it still references to the old data that was stored when user had logged on.
3. It has to be displayed on every page like the Stackoverflow User info at the top
![alt text][1]
[1]:
Which is the best way to do it ?