如何仅更新 Yii 框架中的某些字段? [英] How can I update only certain fields in a Yii framework?

查看:15
本文介绍了如何仅更新 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.

这篇关于如何仅更新 Yii 框架中的某些字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆