错误导致在更新Yii中的新数据时更改密码 [英] Error causes password change while updating new data in Yii

查看:129
本文介绍了错误导致在更新Yii中的新数据时更改密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我尝试使用此函数更新数据库中的AID字段时:

 静态函数aidInsert $ b {
$ model = Users :: model() - > findAll();
foreach($ model as $ m)
{
$ code = alphabeticCode();
$ aidk = Users :: model() - > findByAttributes(array('aid'=> $ code));
if(!empty($ aidk))
{
$ code = alphabeticCode();
}
$ m-> aid = $ code;
$ m-> save();
}
}

(alphabeticCode方法只是一种用于生成随机字符串。)



存储在密码字段中的整个用户密码完全更改为一些md5哈希值,此函数完成后即可。


解决方案

使用 save()默认保存每个属性 - 但您可以指定要保存的属性:

  $ m-> save (true,array('aid')); 
// true使用验证,数组指定要保存的属性


While I'm trying to update the AID field in database with this function:

static function aidInsert()
{
    $model = Users::model()->findAll();
    foreach($model as $m)
    {
        $code = alphabeticCode();
        $aidk = Users::model()->findByAttributes(array('aid'=>$code));
        if(!empty($aidk))
        {
            $code = alphabeticCode();
        }
        $m->aid = $code;
        $m->save();
    }
}

(alphabeticCode Method is just a method used to generate random strings.)

the whole user's password stored in password field is completely changed into some piece of md5 hash, right after this function completed.

Did I do anything wrong?

解决方案

Using save() saves every attribute by default - but you can specify which attributes to save:

$m->save(true, array('aid'));
// true to use validation, the array to specify which attributes to save

这篇关于错误导致在更新Yii中的新数据时更改密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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