Yii Framework Forum: Accessing User Information Without Database Lookup? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Accessing User Information Without Database Lookup?

#1 User is offline   DocSolver 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 12-December 12

Posted 20 November 2013 - 10:47 AM

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
0

#2 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,701
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 20 November 2013 - 11:02 AM

Use Yii::$app->user->identity, it's all there.
Yii::$app->user is just a component.
God is real unless declared as integer
1

#3 User is offline   DocSolver 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 12-December 12

Posted 20 November 2013 - 08:12 PM

View PostORey, on 20 November 2013 - 11:02 AM, said:

Use Yii::$app->user->identity, it's all there.
Yii::$app->user is just a component.

Thanks! This works like a charm!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users