Hello,
I have been using Yii for a few months now, but this is the first time I have had to use it in this way. I have dynamic forms and then yet more dynamic forms dependent on the results of the previous forms. Those dynamic forms can nest any number of fields in the forms. So I chose to serialize the arrays.
To make things easy I did
public function beforeSave(){
parent::beforeSave();
if( is_array( $this->commodity_subtype ) ) // throw the array into the DB.
$this->commodity_subtype = serialize( $this->commodity_subtype );
else if ( !$this->commodity_subtype ) // doesn't exist
$this->commodity_subtype = serialize( array() );
else // single value
$this->commodity_subtype = serialize( array( $this->commodity_subtype ) );
return true;
}
AND
protected function afterFind(){
parent::afterFind();
$this->commodity_subtype = $this->commodity_subtype ? unserialize( $this->commodity_subtype ) : array();
return true;
}
Now, when I submit the form I basically serialize the data into the database. That works. When I go to /form/view/### it works as expected. What does not work as expected is that when I re render the same page – I get an error caused by the still serialized data. Now, let’s say that Save() doesn’t reload the model for an update… I tried to do
refresh() and it did not run through afterFind()… thoughts ?