R
R
ramazan222018-06-26 13:21:31
Yii
ramazan22, 2018-06-26 13:21:31

How to display data from three tables in Yii2?

There are 3 tables:
Profile - with a column - id
Skill-dictionary - id, skill Profile_skill -
id, id_profile,
id_skill in Skill-dictionary It is necessary to display the skill value from Skill-dictionary in the view profile (for the corresponding id profile). in the Profile.php model

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

in profile controller
public function actionIndex()
    {
        $dataProvider = new ActiveDataProvider([
            'query' => Profile::find(),
        ]);

        return $this->render('index', [
            'dataProvider' => $dataProvider,
        ]);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2018-06-26
@Anvi-Vt

You have three tables, two with data, one binder, why do you need to display three?
https://yiiframework.com.ua/ru/doc/guide/2/db-acti...
Linking through an intermediate table

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question