How to create user in database manually in Yii2?

前端 未结 2 1757
感动是毒
感动是毒 2021-01-25 11:35

I do import of users from a csv file to the database. In csv file I have some kinda username and password string. So how do I create a new user manually? As I understand I need

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-25 11:59

    This should be the minimum required in your case. $username and $password are raw values taken from the CSV. Remember that there will be validation applied.

    $user = new User();
    $user->username = $username;
    $user->setPassword($password);
    $user->generateAuthKey();
    
    return $user->save();
    

提交回复
热议问题