Error causes password change while updating new data in Yii

淺唱寂寞╮ 提交于 2019-12-25 02:39:14

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/22221876/error-causes-password-change-while-updating-new-data-in-yii

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!