【发布时间】:2017-07-12 10:21:10
【问题描述】:
我在同一页面上有两个 gridView 小部件,每个小部件都有自己的数据提供者,如下所示:
<?= GridView::widget([
'dataProvider' => $userModel,
'columns' => $columns,
]); ?>
<?= GridView::widget([
'dataProvider' => $companyModel,
'columns' => $columns,
]); ?>
两个视图中的列大体相似,但前三列存在一些差异。我想做的是确定当前正在编译哪个小部件,以便我可以为该小部件动态创建适当的列。例如:
<?php
$columns=[];
// here is where the problem is. I would like to do something along these lines:
if(GridView->dataProvider->id == 'userModel')
{
// add custom columns
$columns[] = 'userName';
} else {
// etc...
}
// common columns used by both grids here
$columns[] = [
'totalCount',
'totalCost',
];
非常感谢任何帮助。
【问题讨论】:
标签: gridview yii2 dataprovider