2014-09-20 70 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