yii2使用Checkbox在GridView中删除多行

时间:2016-03-29 13:10:06

标签: yii2

如何在GridView中使用删除所选对象,在Yii 2 Framework中如下图所示:

enter image description here

<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
    'id',
    'name',
    'created_at:datetime',
    // ...
],

])?&gt;

1 个答案:

答案 0 :(得分:1)

gridView中添加复选框操作列,如

<?= GridView::widget([
   'dataProvider' => $dataProvider,
   'columns' => [
      [
        'class' => 'yii\grid\CheckboxColumn', 'checkboxOptions' => function($data) {
                return ['value' => $data->id];
            },
      ],
      'id',
      'name',
      'created_at:datetime',
      // ...
   ],
 ]) ?>

立即访问控制器中的选定id,如

class YourController extends Controller
{
  public function actionHear()
  {
    if(isset($_REQUEST['selection']))
    {
       ".........Your Code Hear.........."
     }
  }
}