我在yii2中是新手,默认情况下我在gridview中的字段是十进制的,但我的价值属性有一定条件。
我的代码视图看起来像
[
'attribute' => 'harga_diskon_periode',
'format' => function($model){
if($model->diskon_now == ""){
return "text";
}else{
return "decimal";
}
},
'value' => function($model){
if($model->diskon_now == ""){
return "Tidak ada diskon";
}
},
],
所以我需要的是,如果输出编号,格式将是十进制的,如果输出字符串,则格式为文本。
使用上述代码我得到此错误
Object of class Closure could not be converted to string
我读了此http://www.yiiframework.com/doc-2.0/yii-grid-datacolumn.html#qunformat-detail it'show string|array
,所以我在格式属性中使用匿名函数。
我错了吗?我的代码怎么了?我的代码应该如何?我对yii2的新手都将不胜感激。
预先感谢。
gridview不允许在那里闭合,这样做:
'attribute' => 'harga_diskon_periode',
'value' => function ($model) {
return $model->diskon_now == ''
? 'Tidak ada diskon'
: Yii::$app->formatter->asDecimal($model->harga_diskon_periode);
},