更改 DetailView 小部件中的属性值 [英] Changing value of an attribute in DetailView widget

查看:18
本文介绍了更改 DetailView 小部件中的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a table named Play and I'm showing details of each record in Yii2 detail view widget. I have an attribute in that table recurring which is of type tinyint, it can be 0 or 1. But I don't want to view it as a number, instead i want to display yes or no based on the value (0 or 1).

我正在尝试使用 detailview 小部件中的函数来更改它,但出现错误:类闭包的对象无法转换为字符串

I'm trying to change that with a function in detailview widget but I'm getting an error: 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',
        ...

任何帮助将不胜感激!

推荐答案

尝试

'value' => $model->recurring == 1 ? 'yes' : 'no'

这篇关于更改 DetailView 小部件中的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆