Answer the question
In order to leave comments, you need to log in
How to display two models in Gridview?
There are two models Goods
and AddFeild
. Addfeild
linked to Goods
the field id_good
by link hasMany
there is a need to output through Gridview
the content of the model Goods
, and all the data of the associated model Addfeild
. Please don't tell me how this can be done. Or where to find how it is implemented.
Answer the question
In order to leave comments, you need to log in
Create a link in the model:
public function getAddFeild(){
return $this->hasOne(AddFeild::className(),['id_good'=>'id']);
}
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'title',
'addFeild.someAttribute',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question