Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii2 back to previous page after update

How can i redirect user to previous page after updating a record? this is the typical scenario:

  • Users is in index page and filters results or paginates over the records, then they find the one that they want to edit and click the edit button. They update that record's data and once they click on "update" button they whould be redirected to index view but with the filters/page previously selected.

Ive tried using below in my controller after updating

return $this->redirect('index',302); (this is not what I need)

return $this->redirect(Yii::$app->request->referrer); (this gets user back to update view and not to index view with filters)

return $this->goBack(); (this gets user to homepage)

Thanks!

like image 617
farrusete Avatar asked Mar 10 '23 17:03

farrusete


1 Answers

In the action you want user to be redirected to add

\yii\helpers\Url::remember();

Now next call in any controller like:

return $this->goBack();

Will redirect user to the "marked" action.

like image 50
Bizley Avatar answered Mar 18 '23 06:03

Bizley