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
You could also use a getter function to include additional identity information for the user. For example, retrieve fullname
from a profile table.
class User extends ActiveRecord implements \yii\web\IdentityInterface
{
// Other code goes here...
public function getFullname()
{
$profile = Profile::find()->where(['user_id'=>$this->id])->one();
if ($profile !==null)
return $profile->fullname;
return false;
}
}
Then, you can use it as if you have an attribute named fullname
, like so
Yii::$app->user->identity->fullname;