php – Yii2 Pjax删除不起作用
发布时间:2020-12-13 14:09:11 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试使用带有删除按钮的Pjax创建Ajax GridView.删除没有Ajax.我是Yii2的新手,所以任何帮助都将不胜感激.谢谢. 的index.php ?php Pjax::begin(['id' = 'countries']) ??= GridView::widget([ 'dataProvider' = $dataProvider,'columns' = [ ['class' =
我正在尝试使用带有删除按钮的Pjax创建Ajax GridView.删除没有Ajax.我是Yii2的新手,所以任何帮助都将不胜感激.谢谢.
的index.php <?php Pjax::begin(['id' => 'countries']) ?> <?= GridView::widget([ 'dataProvider' => $dataProvider,'columns' => [ ['class' => 'yiigridSerialColumn'],'id','title',['class' => 'yiigridActionColumn','buttons' => [ 'delete' => function ($url,$model,$key) { return Html::a('<span class="glyphicon glyphicon-trash"></span>',$url,[ 'title' => Yii::t('yii','Delete'),'data-confirm' => Yii::t('yii','Are you sure you want to delete this item?'),'data-method' => 'post',]); },] ],],]); ?> <?php Pjax::end() ?> 调节器 public function actionDelete($id) { $model = new Category(); $this->findModel($id)->delete(); $dataProvider = new ActiveDataProvider([ 'query' => Category::find(),]); return $this->render('index',[ 'dataProvider' => $dataProvider,'model' => $model,]); } 这是Controller中的公共函数actionIndex() public function actionIndex() { $model = new Category(); $dataProvider = new ActiveDataProvider([ 'query' => Category::find(),]); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model = new Category(); } return $this->render('index',]); }
数据方法和数据确认不允许您通过pjax创建ajax请求,您应该实现自己的确认对话框并删除POST动词过滤器,或者您可以使用确认对话框并指定http方法来实现您自己的ajax插件.
此外,我认为,必须有通过确认对话框扩展pjax插件的方法,但Yii2默认情况下不提供此功能. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |