在更新记录后,如何将用户重定向到上一页?这是典型的场景:
用户在索引页中,过滤结果或对记录进行分页,然后找到要编辑的记录,然后单击“编辑”按钮。他们更新记录的数据,一旦他们点击“更新”按钮,他们将被重定向到索引视图,但是之前选择了过滤器/页面。
更新后我尝试在我的控制器中使用下面的

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();

接下来调用任何控制器,比如:
return $this->goBack();

将用户重定向到“标记”操作。

07-24 09:44
查看更多