0
A
回答
0
您可以将重定向路径作为GET参数(例如redirectTo
)传递到编辑页面,编辑过程完成后,重定向到该路径。
return new RedirectResponse($request->query->get('redirectTo');
你可以把通过检查是否已提供的参数更强劲,如果不是,重定向到某种默认路径。
1
您的控制器内部为/profile/edit
,您可以使用$request->headers->get('referer')
捕获它们来自的页面。
如果/profile/edit
是一个带有单一窗体的页面,我可能只是添加一个隐藏字段,说明重定向应该放在哪里。
public function editAction(Request $request)
{
// If you have a POST value coming from the user, it will be used, otherwise
// assume this is the first time they landed on the page and grab the current
// referer. With this method it doesn't matter how many times they submit the form
// you won't accidentally overwrite the referer URL with /profile/edit. That could
// lead to a confusing loop.
$referer = $request->request->get('referer', $request->headers->get('referer'));
if ($formIsSaved)
{
return new RedirectResponse($referer)
}
return array(
// Your template should include a hidden field in the form that returns this.
'referer' => $referer,
);
}
相关问题
- 1. Symfony2 - AuthenticationSuccessHandler重定向到原始请求
- 2. 如何nginx的请求重定向到不同的路径
- 3. 将所有请求重定向到IIS中的路径
- 4. cancan/devise - 重定向到请求的路径
- 5. 将请求重定向到路由器
- 6. Symfony2 - FOS UserBundle - 原始请求重定向
- 7. Symfony2重定向所有请求
- 8. CloudFront重定向路径前缀的所有请求
- 9. Apache重定向来自域名+路径的请求
- 10. 路径重定向
- 11. 通过路由重定向请求sails.js
- 12. 在Selenium中阻止或重定向请求到特定路径或域
- 13. 如何将请求重定向到基于亚马逊S3路径的子域
- 14. ASP.Net - 将任何请求重定向到同一路径的另一个域
- 15. 重定向请求
- 16. 如何重定向到特定路径?
- 17. 重新路由请求不发送重定向到客户端
- 18. 在symfony2中用树枝添加属性到路径请求
- 19. MVC 2.0路线,重定向请求,请求忽略
- 20. 检测到循环重定向路径(详情请参阅“重定向路径”部分)
- 21. 如何在重定向Express 4之前找到原始请求路径4
- 22. 后/重定向/获取:重定向到特定路径
- 23. mod_rewrite规则重定向除一个特定路径以外的所有请求
- 24. EmberJS - 将父路径重定向到其嵌套的子路径
- 25. 400错误的请求与Symfony2和html5boilerplate重定向规则
- 26. 重定向到路径以“/”结尾
- 27. 无法重定向到路径?
- 28. will_paginate重定向到根路径
- 29. 重定向到错误路径Phalcon
- 30. 使用AJAX重定向到rails路径
嗨,我想避免与GET参数搞乱:) 会话不能用于这样的事情吗? – bodokaiser 2012-04-02 18:44:15
会话会变得非常混乱 - 在那里,做到了。 – 2012-04-02 18:49:56
其他解决方案? – bodokaiser 2012-04-03 05:45:42