Models relations

Hi , I have this 2 models User and Company , i want from User to get this property:

Yii::$app->user->company, also i have function getCompany(); in User models,

but gets me this error :

Getting unknown property: yii\web\User::company

How can i solve this ? Thanks

make sure your User class have property company and see config file

'user' => [

    'identityClass' => 'app\models\User', 


You must define your identity class inside config.

This may help

'components' => [


'user' => [

    'identityClass' => Your\User\Class,

    'class' => 'yii\web\User',




Yes that works.Thanks