我在控制器中创建了一个带有product
和price
列的SqlDataProvider。
然后,我在视图中使用 GridView 来显示两列,但我需要将$与价格连接起来,以便我可以显示例如75 美元。
我知道如何使用模型来做到这一点,但在这种情况下,我没有模型。
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'product',
[
'attribute' => 'price',
'value' => function($model) {
return '$ ' . $model->price; // I don't have a model so it doesn't work here.
}
],
],
]) ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'product',
[
'attribute' => 'price',
'value' => function ($model) {
return '$ ' . $model['price'];
}
],
],
]) ?>