如何在更新记录后将用户重定向到上一页?这是典型的场景:
- 用户在索引页面中过滤结果或对记录分页,然后他们找到他们想要编辑的那个并点击编辑按钮。他们更新该记录的数据,一旦他们点击“更新”按钮,他们将被重定向到索引 View ,但使用之前选择的过滤器/页面。
我尝试在更新后在我的 Controller 中使用下面
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)
谢谢!
最佳答案
在您希望用户被重定向以添加的操作中
\yii\helpers\Url::remember();
现在在任何 Controller 中进行下一次调用,例如:
return $this->goBack();
将用户重定向到“标记”操作。
关于php - yii2 更新后返回上一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40505215/