相关疑难解决方法(0)

更改DetailView小部件中属性的值

我有一个名为Play的表,我在Yii2详细视图小部件中显示每条记录的详细信息.我在该表中有一个属性recurring为tinyint 的属性,它可以是0或1.但我不想将其视为数字,而是我想显示yesno基于值(0或1).

我正在尝试使用detailview小部件中的函数更改它,但我收到一个错误: Object of class Closure could not be converted to string

我的详细视图代码:

 <?= DetailView::widget([
    'model' => $model,
    'attributes' => [
        'name',
        'max_people_count',
        'type',
        [
             'attribute' => 'recurring',
             'format'=>'raw',
             'value'=> function ($model) {
                        if($model->recurring == 1)
                        {

                            return 'yes';

                        } 
                        else {
                        return 'no';
                        }
                      },
        ],
        'day',
        'time',
        ...
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激 !

detailview yii2

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

detailview ×1

yii2 ×1