farrusete farrusete -3 years ago 401
PHP Question

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!

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download