PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 27, 2022

[FIXED] Yii2 login. Yii::$app->user->login($user, 0) doesnt save

 January 27, 2022     php, session, yii, yii2     No comments   

Issue

I am trying implement login at my site. But seems like Yii::$app->user->login($user, 0) doesn't save identity.

When I've just logged in it work fine:

    if (Yii::$app->user->login($user, 0) ) {
        var_dump(Yii::$app->user->identity);
    } else {
        echo 'didnt login';
    }

var_dump() show identity.

But when I am trying obtain identity in another controller var_dump() shows NULL:

// In other controller
var_dump(Yii::$app->user->identity);

Does somebody know about this problem?


Solution

Okay. Guy in russian yii forum answered the question. (http://yiiframework.ru/forum/viewtopic.php?f=19&t=19135&start=20)

namespace app\models;

use yii\db\ActiveRecord;
use yii\web\IdentityInterface;

class User extends ActiveRecord implements IdentityInterface
{}

I should implement IdentityInterface and I've forgotten. Now it works well!



Answered By - raiym
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing