2013-01-02 2 views
0

에서 Confirm Password (규칙 비교)를 사용할 때 데이터를 업데이트 할 수 없음 등록 양식에서 암호 필드와 암호 확인 필드를 사용하십시오. 사용 후이 데이터는 업데이트 할 수 없습니다. 모델YII 모델

public function rules() 
    { 
      // NOTE: you should only define rules for those attributes that 
      return array(
        array('name, password', 'required'), 
        array('password', 'compare', 'compareAttribute'=>'confirm_password'), 
        array('name', 'length', 'max'=>55), 
        // The following rule is used by search(). 
        // Please remove those attributes that should not be searched. 
        array('id, name', 'safe', 'on'=>'search'), 
      ); 
    } 

`$post= User::model()->findByPk(1); $post->name='Abcdef'; $post->password='newpassword'; $post->save();` 

새로운 데이터가 업데이트되지 index.php를에서 사용자 모델을 업데이트하려고? 그것이 풀릴 때?

답변

-1
public $confirmpassword; 

    public function rules() 
    { 
      // NOTE: you should only define rules for those attributes that 
      return array(
        array('name, password, confirmpassword', 'required'), 
        array('password', 'compare', 'compareAttribute'=>'confirmpassword'), 
        array('name', 'length', 'max'=>55), 
        // The following rule is used by search(). 
        // Please remove those attributes that should not be searched. 
        array('id, name', 'safe', 'on'=>'search'), 
      ); 
    } 
1

confirmpassword이 설정되지 않아 업데이트가 작동하지 않습니다. 업데이트시 암호가 필요하지 않은 경우 암호로 scenario을 포함하면 항상 확인됩니다.

 public function rules() 
    { 
     // NOTE: you should only define rules for those attributes that 
     return array(
       array('name', 'required'), 
       array('password', 'required','on'=>'create'), 
       array('password', 'compare', 'compareAttribute'=>'confirmpassword','on'=>'create'), 
       array('name', 'length', 'max'=>55), 
       // The following rule is used by search(). 
       // Please remove those attributes that should not be searched. 
       array('id, name', 'safe', 'on'=>'search'), 
     );