2012-08-14 128 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')