How to add more user identity session attributes in Yii2?

前端 未结 4 1154
说谎
说谎 2021-02-01 05:54

In Yii2 you can access the identity interface for the current user by using the identityInterface object from within the \\yii\\web\\User class with something like this

4条回答
  •  心在旅途
    2021-02-01 06:30

    The best way to add attributes to user is creating public attribute in your User Class.

    class Yiidentity extends ActiveRecord implements \yii\web\IdentityInterface{
           public $awesomeAttribute = "foo";
    }
    

    How to use:

    Yii::$app->user->identity->awesomeAttribute;
    

提交回复
热议问题