Код: Выделить всё
<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'id',
'headerOptions' => [
'width' => 70,
],
],
[
'attribute' => 'name',
'filter' => false,
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'contentOptions' => ['class' => 'action-column'],
],
],
]); ?>
<?php Pjax::end(); ?>
Код: Выделить всё
class DefaultController extends BaseAdminController
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
public function actionIndex()
{
$searchModel = new ModelSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
protected function findModel($id)
{
if (($model = Model::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
Как сделать AJAX удаление, как было по умолчанию в Yii1 ?