Logs Out User Right After Login

I have a strange issue with session. I’m using a basic template and copied user auth code from advanced app.

So after I fill login info in login form this code executes:

    public function actionLogin()


        if (!\Yii::$app->user->isGuest) {

            return $this->goHome();


        $model = new LoginForm();

        if ($model->load(Yii::$app->request->post()) && $model->login()) {


            echo '<pre>';

            print_r(Yii::$app->user->identity->email); // <- I SEE MY EMAIL HERE

            echo '</pre>';


            return $this->goHome();

        } else {

            return $this->render('login', [

                'model' => $model,




So model validates and logins user. But after $this->goHome(); - user appears on the login page again and logged out (guest). Any ideas why this happens? Maybe its connected somehow to auth_key ?

Ok. Found why it didn’t work…

In basic template there is public property $id defined in User model:

    public $id;

I didn’t remove it when copied code from Advanced template. Not sure why exactly it’s not working when $id is defined as public property, but removing that line helped

Well, it’s because if ID is there, your model is using it instead of database column value.