如何仅更新 Yii 框架中的某些字段?

问题描述:

我不想更新密码字段.如何使用它.我使用 md5 编码作为密码.所以我不想更新 yii 框架中的密码字段.感谢任何帮助??

I dont want to update the password fields.how to use this.Im using md5 encode for password.So i dont want to update the password field in yii framework.any help appreciated??

在您的模型中,您必须执行以下操作:

In your model you must do something like this:

public function rules() {
    return array(
        array('name, username, email, password', 'required', 'on' => 'create'),
        array('name, username, email', 'required', 'on' => 'update'),
    );
}

假设您现在运行的场景是更新.所以我不需要那里的密码.我只在您可能拥有的创建场景中需要它.因此,在您删除密码字段的视图文件中,并在您拥有的操作中包含以下内容:

Lets say that the scenario that you run now is the update. So I don't require the password there. I require it only in the create scenario that you may have. So in the view file that you have you remove the password field and inside the action that you have you include this:

$model->setScenario('update');

所以它不需要密码,它会保持不变.

so it will not require the password and it will remain the same.

对于密码更改,您可以创建一个新操作(例如 actionPassChange),您需要在其中输入两次新密码.

For the password change you can create a new action (ex. actionPassChange) where you will require to type twice the new password.