The fact is, I've been trying to make a password changing form. I've used this approaching so far. I liked it a lot, looks simple, but at the moment I'd like to change password field for the new_password posted in $this->data, at beforeSave it just occurs that posted data is not set.
function beforeSave(){
if(isset($this->data['Usuario']['password_nueva'])){
$this->data['password'] = Security::hash($this->data['Usuario']['password_nueva'], null, true);
}
return $this->data;
}
Looks like cake uses $this->set() method which unsets all the data not related to the model before calling this callback. Is there a way to keep data posted?
I've noticed that $_Post is available, it's not that pretty, but I'll be开发者_如何学编程 using that...
I though this was a good practice coding that way. Is that true?
I can't check right now, but have a look at $this->params
. That's how I get hold of stuff for AJAX (I think).
beforeSave
should be able to see $this->data
- see http://book.cakephp.org/view/683/beforeSave
I'm not sure why it doesn't work. I've checked my user model code and there are some differences. I've rewritten your code:
function beforeSave(){
parent::beforeSave();
if(isset($this->data[$this->name]['password_nueva'])){
$this->data['password'] = Security::hash($this->data[$this->name]['password_nueva'], null, true);
}
return $this->data;
}
精彩评论