我尝试使用yii方案在更新和创建新记录之间分离我的规则。当我把下面的场景放在一起时,记录不会验证表单,并且场景不起作用。我想知道哪里出错了
return array(
array('first_name, second_name, username, password, email, skype, attachment, just, cv', 'required','on'=>'insert'),
array('first_name, second_name, username, password, email', 'required','on'=>'update'),
array('first_name, second_name, username, password, email, skype, status, attachment, just, cv', 'length', 'max'=>255),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('attachment, cv', 'file', 'types'=>'doc, docx, pdf, odt'),
array('re_password','compare','compareAttribute'=>'password'),
);
当我不使用场景时
return array(
array('first_name, second_name, username, password, email, skype, attachment, just, cv', 'required'),
array('first_name, second_name, username, password, email, skype, status, attachment, just, cv', 'length', 'max'=>255),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('attachment, cv', 'file', 'types'=>'doc, docx, pdf, odt'),
array('re_password','compare','compareAttribute'=>'password'),
);
这样可行,但是有一些列我不需要更新来打扰像cv和附件。
请显示一些亮点,因为我遗失了一些东西。
答案 0 :(得分:0)
您需要在使用模型时设置方案。有两种方法可以做到这一点:
$model=new ModelName('SCENARIO_NAME');
或者
$model=new ModelName();
$model->setScenario('SCENARIO_NAME');