Default Db Value Override

When creating new records with Yii, Yii is putting the DB default values for those fields into the form fields.

How can I override this?

One method would be to use the afterFind() method of CActiverecord to replace the default database values


Yes I tried that but it does not replace them, at least it does not on create anyway.


Try overriding afterConstruct().

The constructor is where the defaults are set:

public function __construct($scenario='insert') 


    if($scenario===null) // internally used by populateRecord() and model() 









just insert in your model class

public $field1 = ‘value1’;

public $field2 = ‘value2’;

public $field3 = ‘value3’;

It works in my project :)