2012-08-14 164 views
3

在模型BaseUser.php,我定義$verifyPassword和規則添加它驗證密碼Yii框架

public function rules() { 
     return array(
      array('name, email, phone_code, phone, country, language, password, role, status', 'required'), 
      array('verifyPassword','required', 'on'=>'insert'), 
      array('country, role, status, payment', 'numerical', 'integerOnly'=>true), 
      array('name, email, active_key', 'length', 'max'=>50), 
      array('phone_code', 'length', 'max'=>5), 
      array('phone', 'length', 'max'=>30), 
      array('language', 'length', 'max'=>10), 
      array('password', 'length', 'max'=>32), 
      array('verifyPassword', 'length', 'max'=>32), 
      array('device_token, token', 'length', 'max'=>100), 
      array('created', 'safe'), 
      array('country', 'haveToSelect'), 
      array('email', 'unique', 'message' => Yii::t('app',"This user's email adress already exists.")), 
      array('verifyPassword', 'compare', 'compareAttribute'=>'password'), 
      array('device_token, active_key, token, payment, created', 'default', 'setOnEmpty' => true, 'value' => null), 
      array('id, name, email, phone_code, phone, country, language, password, role, device_token, active_key, status, token, payment, created', 'safe', 'on'=>'search'), 
     ); 
    } 

在ProfileController.php

public function actionIndex() 
    { 

     $data = Yii::app()->session['Authentication']; 
     $idUserLogin = $data->id; 

     $dataUser = Users::model()->findByPk($idUserLogin); 

     if (isset($_POST['Users'])) { 
      $dataUser->setAttributes($_POST['Users']); 

      if($dataUser->save()) { 
       Yii::app()->user->setFlash('success',Yii::t('app','Change profile successful!')); 
       $this->refresh(); 
      } 
     } 

我註冊一個新帳號成功的,但在另一個函數哪些使用profile'user ...我無法保存後更改它。

例如,在按下保存按鈕時功能更改配置文件...沒有任何更改...沒有警報...沒有任何驗證通知。

我該如何解決這個問題?

+0

這聽起來像是在更新方面,在驗證方面失敗了。 你能給我提供一個結果:echo'

'.print_r($dataUser,true).'
';在這行之後:$ dataUser-> setAttributes($ _ POST ['Users']);當你正在嘗試更新? – ews2001 2012-08-14 16:12:33

+0

謝謝......我解決了這個問題.. :) – 2012-08-15 02:16:54

+6

這個問題解決了嗎?如果這是解決方案,那麼請自行發佈並接受爲答案,或者只是刪除問題,但它可以幫助未來的人。 – Paystey 2012-10-26 10:31:07

回答

0

我sloved這個問題......

我改變了規則:

public function rules() { 
    return array(
     array('name, email, phone_code, phone, country, language, password, role, status', 'required'), 
     array('verifyPassword','required', 'on'=>'register'), 
     array('country, role, status, payment', 'numerical', 'integerOnly'=>true), 
     array('name, email, active_key', 'length', 'max'=>50), 
     array('phone_code', 'length', 'max'=>5), 
     array('checkAgree', 'required', 'requiredValue' => 1, 'message' => 'You must have to agree with...', 'on'=>'register'), 
     array('phone', 'length', 'max'=>30), 
     array('language', 'length', 'max'=>10), 
     array('password', 'length', 'max'=>32), 
     array('verifyPassword', 'length', 'max'=>32), 
     array('device_token, token', 'length', 'max'=>100), 
     array('created', 'safe'), 
     array('country', 'haveToSelect'), 
     array('email', 'unique', 'message' => Yii::t('app',"This user's email adress already exists.")), 
     array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'on'=>'register'), 
     array('device_token, active_key, token, payment, created', 'default', 'setOnEmpty' => true, 'value' => null), 
     array('id, name, email, phone_code, phone, country, language, password, role, device_token, active_key, status, token, payment, created', 'safe', 'on'=>'search'), 
    ); 
} 

我檢查 'verifyPassword' 上登記的情況

,並在我的控制器我定義:

$user = new User('register')