had to create this for a project I’m working on, its useful for me, don’t know if someone else would find it useful. but hey beats rewriting the same stuff in the models over and over.
/**
-
CSerializeBehavior allows a model to specify some attributes to be
-
arrays and serialized upon save and unserialized after a Find() function
-
is called on the model.
*<pre>
-
public function behaviors()
-
{
-
return array( -
'CSerializeBehavior' => array( -
'class' => 'application.extensions.CSerializeBehavior', -
'serialAttributes' => array('validator_options'), -
) -
); -
}
-
</pre>
*/
then $model = new Model;
$model->example_attribute = array(‘fun’);
$model->save();
// internally now example_attribute is saved into db as a serialized array
a:1:{i:0;s:3:"fun";}
then $model = Model::model()->find(1);
print_r($model->example_attribute);
Array
(
[0] => fun
)