Reputation: 949
I am working on a CakePHP website, of which most of it works but I am trying to update the users page (which I redirect to for now, once I have it working I am planing on making it an AJAX update). Now the code does work,
if ($this->request->is('post')) {
$this->loadmodel('Setting');
$this->loadmodel('Address');
if ( $this->User->save($this->request->data, $validate = true, $fieldList = array('firstname','surname','homephone','mobilephone','dob','gender')) ) {
$NewUserID = $this->Auth->user('id');
$this->Session->write('Auth', $this->User->read(null,$NewUserID));
$this->Session->setFlash('Update done :)', 'GoodFlashMsg', array(), 'Good');
$this->redirect('/user');
} else {
$this->Session->setFlash('Sorry :( There has been an error, please try again', 'BadFlashMsg', array(), 'Bad');
$this->redirect('/');
}
} //End of POST
Now this does what its meant to, save the updated user details (Address is another table, of which I will do later). But when I re-load the User ID to refresh the Auth Sesssion information, the Address table information seems to be wiped from the Auth Session, as when it re-loads the page on the redirect the address information is blank?
I am just trying to update the Auth information (all of it, the Address Table is linked, via ID, to the User Table) when the user edits any of there information, be it user details or address details.
Thanks.
Upvotes: 0
Views: 119
Reputation: 8100
Compare the array format of user info stored in session before and after your $this->Session->write('Auth', $this->User->read(null,$NewUserID));
statement using debug($_SESSION)
. You will find that array format is not the same. So store info in expected format as your issue will be solved.
Also you should unset the password field before setting info to session.
Upvotes: 2