今天在做订单管理的时候遇到了一个问题。在detailview里我想把支付类型转换成lookup表中对应的中文。
<?= DetailView::widget([
'model' => $model,
'attributes' => [
// 'id',
'order_no',
'username',
'account',
// 'pay_type',
[
'label' => '支付类型',
'attribute'=>'pay_type',
'value' => function () {
return \common\models\Lookup::item('pay_type', $model->pay_type);
},
],
'recharge_type',
'HB_amount',
'balance',
'trade_status',
'trade_no',
'add_time',
'status',
'sum',
'salary',
],
]) ?>
在lookup模型中定义了两个方法:
public static function item($type, $code){
if (!isset(self::$_item_arr[$type])) {
self::itemsLoad($type);
}
return @self::$_item_arr[$type][$code] ? @self::$_item_arr[$type][$code] : false;
}
/**
* 将类的代码、名称关系初始化到静态数组中
* @param $type
*/
public static function itemsLoad($type){
$modles = self::find()->where(['type'=>$type])->orderBy('position asc')->all();
foreach ($modles as $model) {
self::$_item_arr[$type][$model->code] = $model->name;
}
}
然后遇到了这个问题
不知道是什么问题?如果知道的大佬们,请帮小弟解答一下,万分感谢!
已经找到问题,value直接引用方法就可以,不需要写函数。但是新的问题又来了。加函数和不加函数有什么区别呢。?