Modifying a model attribute won't make it to the DB in CActiveRecord::beforeSave()

I’m implementing HTML sanitization for form fields, on the beforeSave() method of a model. But it doesn’t work.

For example:


public function beforeSave()

{

  $this->anAttribute = 'somevalue';

  var_dump( $this->anAttribute );

}

somevalue is actually outputted, but it never gets to the DB, so in between beforeSave() and save() the value is lost and what’s saved is the original form field value.

You should call parent::beforeSave() which will return true as default.

http://www.yiiframework.com/doc/api/1.1/CActiveRecord#beforeSave-detail

/Tommy

beforeSave() must return a boolean value. False (or null in your case) stops saving process.




return parent::beforeSave();