How Can I Define New User->Identity Properties?

I am trying to understand how the whole user identity process works and being fairly new to Yii Framework, I am very confused.

When I echo Yii::$app->user->identity->username; I can get username.

Similarly, when I echo Yii::$app->user->identity->email; I can get the user’s email.

I have added 2 new fields (fName and lName for First Name and Last Name, respectively) to my user table with some test data. How do I properly add these two fields to be able to echo Yii::$app->user->identity->fName; and Yii::$app->user->identity->lName; throughout my application? I cannot seem to find where "email", for example, is populated into user->identity.

Can anyone help? Some sample code would be great if applicable. Thanks!

:blink:

if your identity calss have public property(or some attibures) or method you can access with Yii::$app->user->identity->propertyName or Yii::$app->user->identity->methodName.

if your user class is an ActiveRecord there is nothing you need to do to make them accessable because AR automatically detects the attributes and Yii::$app->user->identity is an instance of your user model class.