@@ -429,43 +429,30 @@ A great way to see the core functionality in action is to look in the
429429Redirecting
430430~~~~~~~~~~~
431431
432- If you want to redirect the user to another page, use the
433- :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::redirect `
434- method::
432+ If you want to redirect the user to another page, use the ``redirectToRoute() `` method::
435433
436434 public function indexAction()
437435 {
438- return $this->redirect($this->generateUrl( 'homepage') );
436+ return $this->redirectToRoute( 'homepage');
439437 }
440438
441- The ``generateUrl() `` method is just a helper function that generates the URL
442- for a given route. For more information, see the :doc: `Routing </book/routing >`
443- chapter.
444-
445- By default, the ``redirect() `` method performs a 302 (temporary) redirect. To
439+ By default, the ``redirectToRoute() `` method performs a 302 (temporary) redirect. To
446440perform a 301 (permanent) redirect, modify the second argument::
447441
448442 public function indexAction()
449443 {
450- return $this->redirect($this->generateUrl( 'homepage') , 301);
444+ return $this->redirectToRoute( 'homepage', 301);
451445 }
452446
453447.. tip ::
454448
455- The ``redirect () `` method is simply a shortcut that creates a ``Response ``
449+ The ``redirectToRoute () `` method is simply a shortcut that creates a ``Response ``
456450 object that specializes in redirecting the user. It's equivalent to::
457451
458452 use Symfony\Component\HttpFoundation\RedirectResponse;
459453
460454 return new RedirectResponse($this->generateUrl('homepage'));
461455
462- .. versionadded :: 2.6
463- You can also directly use
464- :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller::redirectToRoute `
465- and give it directly the route name like :
466-
467- return $this->redirectToRoute('homepage');
468-
469456.. index ::
470457 single: Controller; Rendering templates
471458
@@ -635,7 +622,7 @@ For example, imagine you're processing a form submit::
635622 'Your changes were saved!'
636623 );
637624
638- return $this->redirect($this->generateUrl( ...) );
625+ return $this->redirectToRoute( ...);
639626 }
640627
641628 return $this->render(...);
0 commit comments