Saving to user database table

I’m using yii2-usuario and am trying to save mobile to database

        $user = User::findOne(Yii::$app->user->identity->id);
        $user->scenario = 'update';  
        if (Yii::$app->request->isPost && $user->load(Yii::$app->request->post())) {
            
            if($user->validate()) {
                $user->mobile = $_POST['User']['mobile'];
       
                if (!$user->save(false)) {

                    Yii::$app->response->format = 'json';
                   print_r($user->getErrors()); die;
                }

in my user model i have this

class User extends BaseUser
{
    public $mobile;
    ...
}

in user model i’ve added these to the rules too

 'mobileLength' => ['mobile', 'string', 'max' => 11],

Any idea why? What am i missing here?

If the User is an Active Record class and firstname and lastname are columns in the corresponding table you must not declare them as properties in the class.

1 Like

Heh, I’m looking at this SO question and it looks like you are asking question, get answer here, and then use the answer at SO under different username. Is that correct?

Anyway, I’m happy that Yii knowledge is spread out but that way is fishy.