Validating arrays

Hello,

I have problem with validating arrays. I have model with two fields "key" and "value". I want validate CActiveForm from that model with custom array with datas e.g.:


$tmp = new Model;

$tmp->key = 'something';

$tmp->value = 'value';

$array[] = $tmp;


$tmp = new Model;

$tmp->key = 'different';

$tmp->value = 'value';

$array[] = $tmp;


....


echo CActiveForm::validate($array);

How can I do this?

You can do this:




if($tmp->validate())

{

// Do something

}

Take note that CActiveForm::validate($array) returns a JSON format, not a boolean:

http://www.yiiframework.com/doc/api/1.1/CActiveForm#validate-detail


You can use json_decode(CActiveForm::validate($array));