yii更新并插入场景规则


yii update and insert scenarios rules

我已经尝试使用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'),
            );

这很有效,但有些专栏我不需要更新,比如简历和附件。

请亮灯,因为我错过了什么。

在使用模型时需要设置场景。有两种方法可以做到这一点:

$model=new ModelName('SCENARIO_NAME');

$model=new ModelName();
$model->setScenario('SCENARIO_NAME');