I’m a bit of a noob to the framework so forgive me if I am doing something fundamentally wrong, anyway I have been trying to set this attribute but it won’t set unless I do some hacky stuff. Anyway in my FinanccialReturnController I do this.
public function actionCreate()
{
$model = new FinancialReturn;
if( Yii::app()->request->isPostRequest )
{
$model->setAttributes( $_POST ,true );
$this->_processModel( $model , $_POST );
}
I have an attribute called financial_year_end that I want saved to the DB but it’s not being set. To get to the heart of the matter I went into the CModel code and added some log entries in setAttributes
public function setAttributes($values,$safeOnly=true)
{
if(!is_array($values))
return;
$attributes=array_flip($safeOnly ? $this->getSafeAttributeNames() : $this->attributeNames());
foreach($values as $name=>$value)
{
if(isset($attributes[$name]))
{
Yii::log("BEFORE: $name=$value ");
$this->$name=$value;
Yii::log("AFTER: $name=".$this->$name);
}
else if($safeOnly)
$this->onUnsafeAttribute($name,$value);
}
}
And it reports in the log
BEFORE: financial_year_end=1143806400
AFTER: financial_year_end=
my rules in the FinancialReturn model are
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array_merge(array(
array('financial_year_end', 'required'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('financial_year_end', 'safe'),
array('id', 'safe', 'on'=>'search'),
),parent::rules());
}
Anyway I’m pretty confused as to why financial_year_end is not getting set, any help would be very much appreciated:)