W
W
W1zer2018-09-09 12:27:23
Yii
W1zer, 2018-09-09 12:27:23

How to update the user field when he logs in?

How to make a similarity update_at, but with its own field and value? Without making crutches, increasing with the same code in controllers and models.
According to the idea, it’s logical to somehow competently add your field in the same update_atway without making additional queries to the database, but I would not want to change the Yii2 advanced basic models.
UserController:

public function actionLogin()
    {
        $this->layout = 'login';

        if (!Yii::$app->user->isGuest) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goHome();
        } else {
            $model->password = '';

            return $this->render('login', [
                'model' => $model,
            ]);
        }
    }

In $model->login() the usual validation is comparing passwords.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question