Answer the question
In order to leave comments, you need to log in
Displaying Many to Many result in Yii 2 using GridView?
1. Three tables are given: Email, Categories, Emailcategories
2. Many to Many relationship is implemented (each email can be in different Categories)
3. Using a getter, I get a multidimensional array that contains a category / categories for each email
public function getItems()
{
return $this->hasMany(Categories::className(),['category_id' => 'category_id'])
->viaTable('Emailcategories',['email_id' => 'email_id']);
}
[
'attribute' => 'category_id',
'label' => 'Категория',
'value' => 'items.0.category',
]
Answer the question
In order to leave comments, you need to log in
You can pass an anonymous name to value , and in it you can already form the string you want. Like this:
'value' => function($model) {
return implode(',', $model->items);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question