Answer the question
In order to leave comments, you need to log in
How to correctly display category names in gridview?
In the grid, you need to display the name of the category, we have a category_id
, you can do this:
[
'attribute' => 'category_id',
'content'=>function($data) {
return $data->getCategoryName();
},
]
public function getParent()
{
return $this->hasOne(\app\modules\team\models\TeamCategory::className(), ['id' => 'category_id']);
}
public function getCategoryName()
{
$parent = $this->parent;
return $parent->title ;
}
Answer the question
In order to leave comments, you need to log in
extra requests are caused by the fact that you are using lazy loading, and to output data to the grid it is better to use eager loading , in particular joinWith
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question