3

在模型 BaseUser.php 中,我$verifyPassword在规则中定义并添加了它

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 的功能中...更改后我无法保存。

例如,在按下保存按钮时功能更改配置文件中......没有任何变化......没有任何警报......没有验证通知。

我该如何解决这个问题?

4

1 回答 1

0

我解决了这个问题...

我改变了规则:

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')
于 2014-12-14T10:17:23.253 回答