简体   繁体   中英

Stop Yii2 Pjax Gridview from changing base URL for pagination when using action button

I am adapting this code . It is a Yii2 Gridview with Pjax and action buttons. When I press the delete button, the pjax loads the delete route. The route then deletes the specific model and renders the gridview sans layout, which pjax uses to replace the old Gridview. I have pushState disabled so that the URL stays on the index page.

My problem is that when I press a different page in the pagination menu after pressing delete, Pjax loads the delete page again with the pagination added. It causes a 500 error because the item has already been deleted.

Changing pages before deleting something works fine.

Initial URL: /index.php?r=demo

URL after deleting: /index.php?r=demo

URL after changing page: /index.php?r=demo%2Fdelete&id=60&page=4&per-page=10

How do I prevent the pagination links from pointing to the delete page after I use the delete button?

So the problem was that the demo/delete route was sending a 500 error back to PJAX. When I added a null check on the model that was being deleted, the project started working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM