2014-09-20 45 views
0

我已经尝试使用yii场景来更新和创建新记录之间分开我的规则。当我把下面这些情景放在一起时,记录不会验证表单,情景也不起作用。我不知道我会错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

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

$model=new ModelName('SCENARIO_NAME'); 

或者

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

或者只是'$模型 - >情景= “scenario_name”' – Justinas 2014-10-29 11:40:47

+0

@Justinas你是对的亲爱的。 – 2014-10-29 16:00:39

+0

我不是亲爱的,我是斑马! – Justinas 2014-10-29 17:07:54