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