Storing array data in database

Hello world.

I have a problem with array data and models.

Is there a rule in the models, which serialize arrays before saving in the database and vice versa on select()?

i tried like this:


public function rules()

{

    return array(

        array('food, annotation, date', 'required'),


        array('food', 'type', 'array'),


        array('annotation', 'length', 'max'=>10000),

        array('time_end', 'safe'),

        // The following rule is used by search().

        array('id, annotation, date, time_end', 'safe', 'on'=>'search'),

    );

}

but yii didn’t like this way


Property 'CTypeValidator.0' is not defined.

i sense yii must have the default way.

Please help me.

I am not sure if there’s a rule for ‘array’ type, however you can make your own rule:

array(‘food’, ‘checkFood’);

public function checkFood($attribute, $params)

{

$food = $this->food;

//Check your food array here? Do a $this->addError(‘food’, ‘Error occured’) in case of a validation error.

}

thank you. i’ll use this solution

Reference: Model rules validation. type : CTypeValidator


public function rules()

{

    return array(

        array('food', 'type', 'type' => 'array'),

    );

}