我创建了一个Yii CActiveForm
,其中包含一个字段experience
。现在我已经在相应的Yii模型中需要字段experience
。
现在想要使它只需要一个特定的条件。
让我们说:
if($entity == 'student') {
// make experience required else make experience optional
}
现在我可以为服务器端验证设置一个场景。但是如何根据我的新条件让我的视图显示体验字段的客户端验证。
答案 0 :(得分:-1)
public function rules()
{
return array(
array('experience', 'myRequired'),
);
}
public function myRequired($attribute, $params)
{
if($this->entity == 'student')
{
$this->addError('Experience cannot be blank.');
return false;
}
return true;
}