Remember Url with Parameters Gridview after action Create / Update / Delete

0
2382
views

In this section, we will use remember (helpers/url) to save the specify url. Below is an example

http://localhost:8888/yii/yii2bodyfitstation/backend/web/products/index?sort=-sell_price.
1. The gridview is sorted by sell_price desc.

http://localhost:8888/yii/yii2bodyfitstation/backend/web/products/update?id=3
2. Then we go to update and submit.

http://localhost:8888/yii/yii2bodyfitstation/backend/web/products
3. The url go back to products without parameters. This not same with url in step 1.

To make the url same, we use remember and set specify name. In example, i set as ‘backend_products’.
Add this code into actionIndex in ProductController.php, so every event in gridview like paging, sorting, we remember the url.

Update actionCreate and actionUpdate in ProductsController.php

This mean, after submit create / update, it will redirect.
If previous backend_products is set, go to previous backend_products.
Else to products.

Simple right? Let me know if you have a problem in Yii 2.

Reference :
https://github.com/redzjovi/yii2bodyfitstation/commit/b52e14fa40dc9f92183ce7c05c39ca88c6bfe9a5

LEAVE A REPLY

Please enter your name here
Please enter your comment!