i write a edit function to update user's info, my code:
if($this->request->is('post')){
$this->request->data['User']['password']=Security::hash($this->request->data['User']['password'],'sha1', Configure::read('Security.salt'));
$this->request->data['User']['type'] = '2';
$this->request->data['User']['username'] = $username;
//debug($this->request->data);
if($this->User->validates()){
$this->User->set($this->request->data['User']);
if ($this->User->save($this->request->data,false)) {
$this->Session->setFlash(__('The user has been saved'));
$this->redirect($this->root.'index');
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
}
but i check this function: $this->User->exists() never return true, in my case the User table key is username, when i edit username this function can save new info as new record, but when i didn't edit username, a can't save new info, why it work like this and how can i correct my function to edit a record ?
Try Following steps
if ($this->User->save($this->request->data,false)) {
}