From f4122eeb3770f31f750bb3444eb093785d1db2d2 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 7 Dec 2021 17:57:56 +0100 Subject: [PATCH] Adding redirect to current route Taken from https://github.com/symfony/symfony/issues/44485#issuecomment-987559633 Plus fixing syntax error I missed in https://github.com/symfony/symfony-docs/pull/16206 --- controller.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/controller.rst b/controller.rst index faa9d08e41a..1b2642c4063 100644 --- a/controller.rst +++ b/controller.rst @@ -132,7 +132,7 @@ If you want to redirect the user to another page, use the ``redirectToRoute()`` and ``redirect()`` methods:: use Symfony\Component\HttpFoundation\RedirectResponse; - use Symfony\Component\HttpFoundation\Response + use Symfony\Component\HttpFoundation\Response; // ... public function index(): RedirectResponse @@ -153,6 +153,9 @@ and ``redirect()`` methods:: // redirects to a route and maintains the original query string parameters return $this->redirectToRoute('blog_show', $request->query->all()); + + // redirects to the current route (e.g. for Post/Redirect/Get pattern): + return $this->redirectToRoute($request->attributes->get('_route')); // redirects externally return $this->redirect('http://symfony.com/doc');