如何在Yii 2 GridView中使用复选框显示属性值

时间:2016-06-10 00:44:31

标签: checkbox yii

我想将mission_id放入复选框

$req = 'select c.mission_id as mission_id, c.user_id as user_id from order c';

    $dataProvider = new SqlDataProvider([
            'sql' => $req,
    ]);

    return $this->render('factures', [
        'dataProvider' => $dataProvider,
    ]);
_index.php中的

    <?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'mission_id',
        'user_id',

    ],
]); ?>

这没关系,但是当我使用复选框时,它就是KO:试图获取非对象的属性

[
            'attribute' => 'id',
            'format' => 'raw',
            'value' => function($data) {
                return '<input type="checkbox" name="chk_group" value="'.$data->mission_id.'" />Mission : '.$data->mission_id;
            },
        ],

请帮助

1 个答案:

答案 0 :(得分:0)

一些回应:试图获取非对象的属性:

                [
            'attribute' => 'id',
            'format' => 'raw',
            'value' => function($model) {
            return '<input type="checkbox" name="chk_group" value="'.$model->mission_id.'" />Mission : '.$model->mission_id;
            },
            ],