Actually, I need this in order to use links with other models. For example, there is an Adduserfield model, which is so connected with the User model.

public function getAdduserfeild(){ return $this->hasOne(Adduserfeild::className(),['id_user'=>'id']); } 

How can I get the fields from the Adduserfield model of the logged in user?

    2 answers 2

    This is your relaying in the User model.

     public function getAdduserfeild(){ return $this->hasOne(Adduserfeild::className(),['id_user'=>'id']); } 

    So use it

     $fields = (!Yii::$app->user->isGuest) ? Yii::$app->user->identity->adduserfeild : null; 

      Maybe so.

       public function getAdduserfeild(){ return $this->hasOne(Adduserfeild::className(),['id_user'=> Yii::$app->user->identity->id])->one(); }