Yii2数据方法帖子在gridView中不起作用

时间:2016-09-29 14:22:19

标签: gridview yii2

在gridView的dataColumn的单元格中,我放置了一个data-method = post的链接,以及一个data-confirm ='Some confirm vessage'。但是,当您单击链接时,它与get方法一起使用,并且不显示确认消息。为什么它不起作用? 这是代码:

<?= GridView::widget([
        'dataProvider' => new ArrayDataProvider([
            'allModels' => $model->orders
        ]),
        'columns' => [
            //... some other columns .... Then:
            [
                'headerOptions' => ['class' => 'bg-teal color-palette'],
                'footerOptions' => ['class' => 'bg-teal color-palette'],
                'format' => 'html',
                'value' => function($model)
                {
                    return Html::a(
                        'Delete',
                        [
                            'order/delete',
                            'id' => $model->id
                        ],
                        [
                            'class' => 'btn btn-primary btn-block',
                            'data-confirm' => 'Do you realy want to delete the item?',
                            'data-method' => 'post',
                        ]
                    );
                }
            ],
    ]); ?>

如果我将Html :: a放在gridView之外,它可以正常工作。我做错了吗?

1 个答案:

答案 0 :(得分:5)

您的格式&#39;数据单元的属性需要是“原始”的。在这种情况下,作为&#39; html&#39;过滤了很多东西。

<?= GridView::widget([
    'dataProvider' => new ArrayDataProvider([
        'allModels' => $model->orders
    ]),
    'columns' => [
        //... some other columns .... Then:
        [
            'headerOptions' => ['class' => 'bg-teal color-palette'],
            'footerOptions' => ['class' => 'bg-teal color-palette'],
            'format' => 'raw',
            'value' => function($model)
            {
                return Html::a(
                    'Delete',
                    [
                        'order/delete',
                        'id' => $model->id
                    ],
                    [
                        'class' => 'btn btn-primary btn-block',
                        'data-confirm' => 'Do you realy want to delete the item?',
                        'data-method' => 'post',
                    ]
                );
            }
        ],
]); ?>