我想在GridView :: widget中添加一列
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'owner_id',
'situation',
'address',
[
// 'attribute' => 'address',
'format' => 'html',
'label' => 'Image',
'value' => function ($data) {
return Html::img('http://iicity.ir/' . $data['address'],
['width' => '60px']);
},
],
'slideshow_text',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
我想从另一个表中添加’owner_id’的名称
名称在(帐户)表中
表:
id = 1 name = jack
id = 2 name = Sara
解决方法:
use app\models\Account;
...
[
'attribute' => 'owner_id',
'value' => function ($model) {
$info = Account::findOne(['id' => $model->owner_id]);
return isset($info->name) ? $info->name : $model->owner_id;
},
],