Skip to content

Commit f4122ee

Browse files
Adding redirect to current route
Taken from symfony/symfony#44485 (comment) Plus fixing syntax error I missed in #16206
1 parent 29c2bec commit f4122ee

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

controller.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ If you want to redirect the user to another page, use the ``redirectToRoute()``
132132
and ``redirect()`` methods::
133133

134134
use Symfony\Component\HttpFoundation\RedirectResponse;
135-
use Symfony\Component\HttpFoundation\Response
135+
use Symfony\Component\HttpFoundation\Response;
136136

137137
// ...
138138
public function index(): RedirectResponse
@@ -153,6 +153,9 @@ and ``redirect()`` methods::
153153

154154
// redirects to a route and maintains the original query string parameters
155155
return $this->redirectToRoute('blog_show', $request->query->all());
156+
157+
// redirects to the current route (e.g. for Post/Redirect/Get pattern):
158+
return $this->redirectToRoute($request->attributes->get('_route'));
156159

157160
// redirects externally
158161
return $this->redirect('http://symfony.com/doc');

0 commit comments

Comments
 (0)