douqian2334 2014-08-01 09:45
浏览 275
已采纳

Yii2登录 Yii :: $ app-> user-> login($ user,0)不保存

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?

  • 写回答

1条回答 默认 最新

  • dsghpgmay31938863 2014-08-05 09:22
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 cplex运行后参数报错是为什么
  • ¥15 之前不小心删了pycharm的文件,后面重新安装之后软件打不开了
  • ¥15 vue3获取动态宽度,刷新后动态宽度值为0
  • ¥15 升腾威讯云桌面V2.0.0摄像头问题
  • ¥15 关于Python的会计设计
  • ¥15 聚类分析 设计k-均值算法分类器,对一组二维模式向量进行分类。
  • ¥15 stm32c8t6工程,使用hal库
  • ¥15 找能接spark如图片的,可议价
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 博通raid 的写入速度很高也很低