yii2更新后返回上一页

时间:2016-11-09 10:53:01

标签: php yii2 yii2-advanced-app

如何在更新记录后将用户重定向到上一页?这是典型的情况:

  • 用户位于索引页面中并过滤记录中的结果或分页,然后他们找到要编辑的那个,然后单击编辑按钮。他们更新了该记录的数据,一旦他们点击了"更新"按钮,他们将被重定向到索引视图,但前面已选择过滤器/页面。

我在更新后尝试在我的控制器中使用下面的

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)

谢谢!

1 个答案:

答案 0 :(得分:7)

在您希望用户重定向到添加

的操作中
\yii\helpers\Url::remember();

现在接下来打电话给任何控制器,如:

return $this->goBack();

将用户重定向到"标记为"动作。