如何在GridView中使用删除所选对象,在Yii 2 Framework中如下图所示:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'id',
'name',
'created_at:datetime',
// ...
],
])?&gt;
答案 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.........."
}
}
}