Answer the question
In order to leave comments, you need to log in
Yii2 get GriwView records?
There is such a database structure: It is necessary to display all authors for one book in a separate GridView
column .
I tried in the Authors model, to make such a connection:
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthorsBooks()
{
return $this->hasMany(AuthorsBooks::className(), ['authors_id' => 'id'])->viaTable('books', ['id' => 'books_id']);
}
Answer the question
In order to leave comments, you need to log in
....
[
'attribute'=>'authorsBooks',
'value'=>function($model){
return implode(',',ArrayMap::getColumn($model->authorsBooks,'name'));
}
]
...
public function getAutorsString(){
return implode(',',ArrayMap::getColumn($this->authorsBooks,'name'));
}
....
[
'attribute'=>'authorsBooks',
'value'=>'autorsString'
]
...
GridView::widget([
...
'columns' => [
...
'author' => [
'label' => 'Авторы',
'format' => 'html',
'value' => function (Book $book) {
foreach($book->authorsBooks...
return ...;
},
],
],
])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question