Rules are dynamically built from a database table. I’m trying to use thyseus extension (http://www.yiiframework.com/extension/yii-user-management) with lot of customization, so there is no a direct rule code.
Anyway, following the code I’m using now to dynamically build the rules:
if ($field->related_field_name)
{
$parts = explode(';', $field->related_field_name);
if (count($parts) == 1):
$split = explode(':', $parts[0]);
$validatingField = $split[0];
$compareValue = $split[1];
$rules[] = array(
$field->varname,
'EConditionalValidator',
'conditionalRules' => array($validatingField, 'compare', 'compareValue'=>$compareValue),
'rule' => array('required'),
);
else:
$conditionalRules = array();
foreach ($parts as $part) {
$split = explode(':', $part);
$validatingField = $split[0];
$compareValue = $split[1];
$conditionalRules[] =
array(
$validatingField,
'compare',
'compareValue' => $compareValue,
);
}
$rules[] = array(
$field->varname,
'EConditionalValidator',
'conditionalRules' => array(
'group'=>$conditionalRules,
),
'rule'=>array('required'),
);
endif;
}
In the future I will do a method to manage rules different from ‘required’, but at the moment I need only this kind of rule type. No time to do it now