There are 3 tables:

Profile (id) Skill-dictionary (id, skill) Profile_skill (id, id_profile, id_skill) 

Profile_skill is associated with two other tables by foreign keys fk_profile-skill_profile - id_profile -> id in the profile table fk_profile-skill_skill - id_skill -> id in Skill-dictionary

It is necessary to deduce the value of Skill-dictionary in the view profile (for the corresponding id in the profile ).

In the Profile.php model:

 public function getProfileSkills() { return $this->hasMany(ProfileSkill::className(), ['id_profile' => 'id']) ->joinWith(['id ProfileSkill']) ->joinWith(['id SkillDictionary']); } 

In the Profile controller:

 public function actionIndex() { $dataProvider = new ActiveDataProvider([ 'query' => Profile::find(), ]); return $this->render('index', [ 'dataProvider' => $dataProvider, ]); } 

    2 answers 2

    You asked this question yesterday and they gave you the answer.

    Then you asked this question here and you also gave an answer to it.

    Can you stop making threads and read documentation off Yii2?

    • The answers given to me do not work. Those. On the fact of the answer there are no - Roman Petrov
    • In fact, you are too lazy to spend 2 minutes and read the documentation. Follow the link that I gave you, and find the description of the joinWith method there and compare it with what you wrote - madfan41k

    I can offer this option: 1. in the Profile_skill model, register two hasOne() links with the Skill and Profile tables. For example, to contact Skill:

     public function getNameSkill(){ return $this->hasOne(Skill::className(), ['id' => 'id_skill']); } //Аналогично и для Profile 

    2. use eager loading when executing the Profile :: find () query, simply by doing the following: Profile :: find () -> with (). And further, when in the view you will need to display the name of the skill, do this:

     //внутри виджета GridView: 'columns' => [ ... [ 'attribute' => 'id_skill', 'value' => function($data){ return $data->nameSkill->skill; }, ], ... ], 

    I hope this answer will help you (: