如何在GridView yii2中显示可选数据

时间:2014-11-21 09:33:53

标签: php yii2

我有现场"状态"在我的表中,字段值为1或2。 我希望显示GridView yii2,如果1然后激活,如果2则不激活

1 个答案:

答案 0 :(得分:1)

[   
        'format' => 'html',
        'attribute' => 'field_name',
        'value' => function($data) {
            return ($data->field_name == 1 ? 'active' : 'not active');
        },
    ],

您可以尝试使用此代码