Where should I put statements that modify data, some of which is validated input, before it is saved to table?
Specifically, where should I put a $this->User->password = crypt('$this->User->password','hg');
statement? Is this statement correct?
It's best to use one of the standard callbacks to intercept a save (or create, or update) and change something to an attribute.
My code for a login system in which an password entered by a new user is encrypted before being saved to the database: in the model:
function beforeCreate()
{
$this->encryptPassword();
return true;
}
function encryptPassword()
{
$this->set('password_encrypted', sha1($this->get('password')));
}
But in this example the encrypted password is kept in another attribute (password_encrypted) than the original (password)
More info on the Active Record callbacks in the API docs
1 to 2 of 2