Reputation: 8530
I have a User Model, a UsersController and an AccountController which uses the User Model (the account controller is used when an account is created, login, logout).
Everything works fine, except the beforeSave function in AccountController. I'm trying to use beforeSave to hash my password but it doesn't work (the password is saved un-hashed in the database).
public function beforeSave() {
parent::beforeSave();
if (isset($this->request->data['User']['password'])) {
$this->request->data['User']['password'] = sha1($this->request->data['User']['password']);
}
return true;
}
A few notes:
return false;
the save function is still executed (which I thought should not be the casedebug($this->request->data)
gives me nothingI think in my case beforeSave is not being called, I just can't figure out why.
Solved: The beforeSave function has to go inside the model, this is my beforeSave function now:
public function beforeSave($options = array()) {
parent::beforeSave();
$this->data['User']['password'] = sha1($this->data['User']['password']);
return true;
}
Upvotes: 4
Views: 5787