Answer the question
In order to leave comments, you need to log in
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']);
}
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question