Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 redirect to previous page

Tags:

yii2

Now My application is using gridview to list all information and it's also have pagination.when the user click on pagination number and then click on edit and then save. It redirect user to view page. What I want to do it to redirect user to previous page(url with pagination number).

like image 365
Chhorn Soro Avatar asked Feb 17 '15 03:02

Chhorn Soro


1 Answers

You could use Yii::$app->request->referrer which returns the last page the user was on.

Usage is straightforward:

return $this->redirect(Yii::$app->request->referrer); 

You need also take into account that referrer can be null:

return $this->redirect(Yii::$app->request->referrer ?: Yii::$app->homeUrl); 

See the docs.

like image 164
deacs Avatar answered Sep 19 '22 17:09

deacs