Accessing User Information Without Database Lookup?

Hi,

I have my own User model, which is configured as the identityClass in the configuration.

During runtime I would like to access some information about the current user, and also related models (like the company he belongs to).

However, when I access Yii::$app->user it doesn’t give me access to these variables and related models.

However, when I do a print_r of Yii::$app->user, I can see that is has loaded my own user model with all its custom properties in [_identity:yii\web\User:private].

How could I easily access this kind of information? Do I need to do a separate AR lookup in the controller and pass the model to the view, or is there a way to do this through the Yii::$app->user object?

Or can I automatically make such an object available in all views?

Best regards

Vincent

Use Yii::$app->user->identity, it’s all there.

Yii::$app->user is just a component.

Thanks! This works like a charm!