Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
If I understand you correctly, then something like this:
Let's say you have Books and Authors models. And you want to display a list of books with the name of the author in the GridView.
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'title',
'author' => [
'class' => \yii\grid\DataColumn::className(),
'format' => 'html',
'value' => function ($model, $index, $widget) {
return $model->author->name ;
},
],
// и т.п. ...
public function getAuthor() {
return $this->hasOne(Authors::className(), ['id' => 'author_id']);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question