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?
Page 1 of 1
Default Db Value Override
#2
Posted 10 December 2012 - 05:12 PM
One method would be to use the afterFind() method of CActiverecord to replace the default database values
#3
Posted 11 December 2012 - 07:24 AM
#4
Posted 11 December 2012 - 08:24 AM
Try overriding afterConstruct().
The constructor is where the defaults are set:
The constructor is where the defaults are set:
public function __construct($scenario='insert')
{
if($scenario===null) // internally used by populateRecord() and model()
return;
$this->setScenario($scenario);
$this->setIsNewRecord(true);
$this->_attributes=$this->getMetaData()->attributeDefaults;
$this->init();
$this->attachBehaviors($this->behaviors());
$this->afterConstruct();
}
#5
Posted 11 December 2012 - 09:03 AM
just insert in your model class
public $field1 = 'value1';
public $field2 = 'value2';
public $field3 = 'value3';
It works in my project
public $field1 = 'value1';
public $field2 = 'value2';
public $field3 = 'value3';
It works in my project
Share this topic:
Page 1 of 1

Help














