You are viewing revision #1 of this wiki article.
This is the latest version of this article.
in model add the following code:
public function multiItemRequired($attribute,$params)
{
if(empty($this->$attribute))
{
$required = false;
$item = explode(',',$params['compare']);
foreach($item as $attr)
{
if(($value = trim($this->$attr)) && !empty($value))
{
$required = true;
break;
}
}
if($required === false)
{
$field = end($item);
$this->addError($field,Yii::t('core',$field.' cannot be blank'));
}
}
else
return;
}
so you can use like this
public function rules()
{
return array(
...
array('field','multiItemRequired','compare'=>'type,title,other'),
...
);
}
if your rules fields is custom,you must be special a safe rule
...
public $type;
public $title;
public $other;
public function rules()
{
return array(
...
array('type,title,other','safe'),
...
);
}
...
also in a scenario
public function rules()
{
return array(
...
array('field','multiItemRequired','compare'=>'type,title,other','on'=>'scenario'),
...
);
}
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.