Reputation: 14141
In cakephp 2 I have a form that creates a new record into the companies and users table.
My problem is that it saves into both table but in the Umuser table it does not hash the passwords or id key. It does not seem to call anything the the Umuser model at all. The is a before save and it does not call that.
public function beforeSave() {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
The Umuser is in the puging/Usermin/Models directory.
The company controller to save the data:
public function add() {
if ($this->request->is('post')) {
$this->Company->create();
if ($this->Company->saveAll($this->request->data, array('validate'=>'first'))) { // Should ensure both sets of model data get validated
$this->Session->setFlash(__('The company has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The company could not be saved. Please, try again.'));
}
}
}
Cant see why it save the data but bypasses the Umuser model to do it.
Upvotes: 0
Views: 1670
Reputation: 15350
$this->data[$this->alias]['password']) Probably someting wrong here. Try to do something like this:
public function beforeSave() {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
return true;
}else{
return false; // if $this->data[$this->alias]['password'] is not set, don't save the model
}
}
then post here if the company has been saved
Upvotes: 1