From ccc6384ddde274cde5c36eb2d7248c704ce76962 Mon Sep 17 00:00:00 2001 From: Thomas Royer Date: Fri, 8 Aug 2014 16:33:04 +0200 Subject: [PATCH 1/8] Added shortcut methods for controllers --- book/controller.rst | 8 ++++++++ book/security.rst | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/book/controller.rst b/book/controller.rst index 6a451037e7b..55ccccf5ee3 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -451,6 +451,10 @@ perform a 301 (permanent) redirect, modify the second argument:: return new RedirectResponse($this->generateUrl('homepage')); + You can also directly use ``redirectToRoute()`` and give it directly the route name like : + + return $this->redirectToRoute('homepage'); + .. index:: single: Controller; Forwarding @@ -720,6 +724,10 @@ After processing the request, the controller sets a ``notice`` flash message and then redirects. The name (``notice``) isn't significant - it's just what you're using to identify the type of the message. +.. tip:: + + You can use the ``addFlash(...)`` method as a shortcut to ``$this->get('session')->getFlashBag()->add(...)``. + In the template of the next action, the following code could be used to render the ``notice`` message: diff --git a/book/security.rst b/book/security.rst index 0572bc13330..474b8822e62 100644 --- a/book/security.rst +++ b/book/security.rst @@ -1124,6 +1124,11 @@ Thanks to the SensioFrameworkExtraBundle, you can also secure your controller us For more information, see the :doc:`FrameworkExtraBundle documentation `. +.. tip:: + + You can use directly `$this->isGranted($role)` instead of `$this->get('security.context')->isGranted($role)` to check if + a role is granted and `denyAccessUnlessGranted` to throw an exception if the access is not granted (like in the example above). + Securing other Services ~~~~~~~~~~~~~~~~~~~~~~~ From 3b03455fb2f54b8012f67cc245eedca23a3cf112 Mon Sep 17 00:00:00 2001 From: Thomas Royer Date: Fri, 8 Aug 2014 17:12:43 +0200 Subject: [PATCH 2/8] Minor format improvements --- book/controller.rst | 11 +++++++---- book/security.rst | 9 +++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/book/controller.rst b/book/controller.rst index 55ccccf5ee3..55c46854dda 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -451,7 +451,10 @@ perform a 301 (permanent) redirect, modify the second argument:: return new RedirectResponse($this->generateUrl('homepage')); - You can also directly use ``redirectToRoute()`` and give it directly the route name like : +.. versionadded:: 2.6 + You can also directly use + :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::redirectToRoute`` + and give it directly the route name like : return $this->redirectToRoute('homepage'); @@ -724,9 +727,9 @@ After processing the request, the controller sets a ``notice`` flash message and then redirects. The name (``notice``) isn't significant - it's just what you're using to identify the type of the message. -.. tip:: - - You can use the ``addFlash(...)`` method as a shortcut to ``$this->get('session')->getFlashBag()->add(...)``. +.. versionadded:: 2.6 + You can use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::addFlash`` + method as a shortcut to ``$this->get('session')->getFlashBag()->add(...)``. In the template of the next action, the following code could be used to render the ``notice`` message: diff --git a/book/security.rst b/book/security.rst index 474b8822e62..b85382df4c2 100644 --- a/book/security.rst +++ b/book/security.rst @@ -1124,10 +1124,11 @@ Thanks to the SensioFrameworkExtraBundle, you can also secure your controller us For more information, see the :doc:`FrameworkExtraBundle documentation `. -.. tip:: - - You can use directly `$this->isGranted($role)` instead of `$this->get('security.context')->isGranted($role)` to check if - a role is granted and `denyAccessUnlessGranted` to throw an exception if the access is not granted (like in the example above). +.. versionadded:: 2.6 + You can use directly `$this->isGranted($role)` instead of + `$this->get('security.context')->isGranted($role)` to check if + a role is granted and `denyAccessUnlessGranted` to throw an exception + if the access is not granted (like in the example above). Securing other Services ~~~~~~~~~~~~~~~~~~~~~~~ From 675877dedc02a6ca07801bba858bb2aa5f3b3c6f Mon Sep 17 00:00:00 2001 From: Thomas Royer Date: Fri, 8 Aug 2014 17:15:55 +0200 Subject: [PATCH 3/8] Minor improvements --- book/controller.rst | 4 ++-- book/security.rst | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/book/controller.rst b/book/controller.rst index 55c46854dda..2ad384981af 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -453,7 +453,7 @@ perform a 301 (permanent) redirect, modify the second argument:: .. versionadded:: 2.6 You can also directly use - :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::redirectToRoute`` + :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::redirectToRoute` and give it directly the route name like : return $this->redirectToRoute('homepage'); @@ -728,7 +728,7 @@ and then redirects. The name (``notice``) isn't significant - it's just what you're using to identify the type of the message. .. versionadded:: 2.6 - You can use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::addFlash`` + You can use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::addFlash` method as a shortcut to ``$this->get('session')->getFlashBag()->add(...)``. In the template of the next action, the following code could be used to render diff --git a/book/security.rst b/book/security.rst index b85382df4c2..f061fa43642 100644 --- a/book/security.rst +++ b/book/security.rst @@ -1125,10 +1125,10 @@ For more information, see the :doc:`FrameworkExtraBundle documentation `. .. versionadded:: 2.6 - You can use directly `$this->isGranted($role)` instead of - `$this->get('security.context')->isGranted($role)` to check if - a role is granted and `denyAccessUnlessGranted` to throw an exception - if the access is not granted (like in the example above). + You can use directly :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::isGranted` + instead of `$this->get('security.context')->isGranted($role)` to check if + a role is granted and :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::denyAccessUnlessGranted` + to throw an exception if the access is not granted (like in the example above). Securing other Services ~~~~~~~~~~~~~~~~~~~~~~~ From 0366a0c7a58f3f30ea3a3c0ef2ec81405bdb014b Mon Sep 17 00:00:00 2001 From: Thomas Royer Date: Tue, 30 Sep 2014 09:18:55 +0200 Subject: [PATCH 4/8] redirect changed to redirectToRoute --- book/controller.rst | 23 ++++++----------------- book/doctrine.rst | 2 +- book/forms.rst | 6 +++--- book/propel.rst | 2 +- book/validation.rst | 2 +- components/form/introduction.rst | 2 +- cookbook/doctrine/file_uploads.rst | 6 +++--- cookbook/doctrine/registration_form.rst | 2 +- cookbook/form/direct_submit.rst | 6 +++--- cookbook/form/form_collections.rst | 2 +- quick_tour/the_controller.rst | 8 ++------ 11 files changed, 23 insertions(+), 38 deletions(-) diff --git a/book/controller.rst b/book/controller.rst index 2ad384981af..87dd1fb5894 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -423,41 +423,30 @@ to manage in Symfony2. Redirecting ~~~~~~~~~~~ -If you want to redirect the user to another page, use the ``redirect()`` method:: +If you want to redirect the user to another page, use the ``redirectToRoute()`` method:: public function indexAction() { - return $this->redirect($this->generateUrl('homepage')); + return $this->redirectToRoute('homepage'); } -The ``generateUrl()`` method is just a helper function that generates the URL -for a given route. For more information, see the :doc:`Routing ` -chapter. - -By default, the ``redirect()`` method performs a 302 (temporary) redirect. To +By default, the ``redirectToRoute()`` method performs a 302 (temporary) redirect. To perform a 301 (permanent) redirect, modify the second argument:: public function indexAction() { - return $this->redirect($this->generateUrl('homepage'), 301); + return $this->redirectToRoute('homepage', 301); } .. tip:: - The ``redirect()`` method is simply a shortcut that creates a ``Response`` + The ``redirectToRoute()`` method is simply a shortcut that creates a ``Response`` object that specializes in redirecting the user. It's equivalent to:: use Symfony\Component\HttpFoundation\RedirectResponse; return new RedirectResponse($this->generateUrl('homepage')); -.. versionadded:: 2.6 - You can also directly use - :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::redirectToRoute` - and give it directly the route name like : - - return $this->redirectToRoute('homepage'); - .. index:: single: Controller; Forwarding @@ -717,7 +706,7 @@ For example, imagine you're processing a form submit:: 'Your changes were saved!' ); - return $this->redirect($this->generateUrl(...)); + return $this->redirectToRoute(...); } return $this->render(...); diff --git a/book/doctrine.rst b/book/doctrine.rst index 84a54b49017..17305f33992 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -675,7 +675,7 @@ you have a route that maps a product id to an update action in a controller:: $product->setName('New product name!'); $em->flush(); - return $this->redirect($this->generateUrl('homepage')); + return $this->redirectToRoute('homepage'); } Updating an object involves just three steps: diff --git a/book/forms.rst b/book/forms.rst index ded2449c47b..2e3f85d594f 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -225,7 +225,7 @@ controller:: if ($form->isValid()) { // perform some action, such as saving the task to the database - return $this->redirect($this->generateUrl('task_success')); + return $this->redirectToRoute('task_success'); } // ... @@ -304,7 +304,7 @@ querying if the "Save and add" button was clicked:: ? 'task_new' : 'task_success'; - return $this->redirect($this->generateUrl($nextAction)); + return $this->redirectToRoute($nextAction); } .. index:: @@ -1197,7 +1197,7 @@ it after a form submission can be done when the form is valid:: $em->persist($task); $em->flush(); - return $this->redirect($this->generateUrl('task_success')); + return $this->redirectToRoute('task_success'); } If, for some reason, you don't have access to your original ``$task`` object, diff --git a/book/propel.rst b/book/propel.rst index 6b239374e64..0297388caf4 100644 --- a/book/propel.rst +++ b/book/propel.rst @@ -231,7 +231,7 @@ have a route that maps a product id to an update action in a controller:: $product->setName('New product name!'); $product->save(); - return $this->redirect($this->generateUrl('homepage')); + return $this->redirectToRoute('homepage'); } Updating an object involves just three steps: diff --git a/book/validation.rst b/book/validation.rst index 127b666709c..bb7fd97fcb6 100644 --- a/book/validation.rst +++ b/book/validation.rst @@ -231,7 +231,7 @@ workflow looks like the following from inside a controller:: if ($form->isValid()) { // the validation passed, do something with the $author object - return $this->redirect($this->generateUrl(...)); + return $this->redirectToRoute(...); } return $this->render('BlogBundle:Author:form.html.twig', array( diff --git a/components/form/introduction.rst b/components/form/introduction.rst index f65556defc9..74a4b5cca07 100644 --- a/components/form/introduction.rst +++ b/components/form/introduction.rst @@ -544,7 +544,7 @@ method: // ... perform some action, such as saving the data to the database - return $this->redirect($this->generateUrl('task_success')); + return $this->redirectToRoute('task_success'); } // ... diff --git a/cookbook/doctrine/file_uploads.rst b/cookbook/doctrine/file_uploads.rst index ab90001194e..01da6f18879 100644 --- a/cookbook/doctrine/file_uploads.rst +++ b/cookbook/doctrine/file_uploads.rst @@ -244,7 +244,7 @@ The following controller shows you how to handle the entire process:: $em->persist($document); $em->flush(); - return $this->redirect($this->generateUrl(...)); + return $this->redirectToRoute(...); } return array('form' => $form->createView()); @@ -267,7 +267,7 @@ in a moment to handle the file upload:: $em->persist($document); $em->flush(); - return $this->redirect(...); + return $this->redirectToRoute(...); } The ``upload()`` method will take advantage of the :class:`Symfony\\Component\\HttpFoundation\\File\\UploadedFile` @@ -431,7 +431,7 @@ call to ``$document->upload()`` should be removed from the controller:: $em->persist($document); $em->flush(); - return $this->redirect(...); + return $this->redirectToRoute(...); } .. note:: diff --git a/cookbook/doctrine/registration_form.rst b/cookbook/doctrine/registration_form.rst index 4e4abbb5a05..b6849791212 100644 --- a/cookbook/doctrine/registration_form.rst +++ b/cookbook/doctrine/registration_form.rst @@ -287,7 +287,7 @@ the validation and saves the data into the database:: $em->persist($registration->getUser()); $em->flush(); - return $this->redirect(...); + return $this->redirectToRoute(...); } return $this->render( diff --git a/cookbook/form/direct_submit.rst b/cookbook/form/direct_submit.rst index 5a40a0aec3f..faa5e683221 100644 --- a/cookbook/form/direct_submit.rst +++ b/cookbook/form/direct_submit.rst @@ -25,7 +25,7 @@ submissions:: if ($form->isValid()) { // perform some action... - return $this->redirect($this->generateUrl('task_success')); + return $this->redirectToRoute('task_success'); } return $this->render('AcmeTaskBundle:Default:new.html.twig', array( @@ -64,7 +64,7 @@ method, pass the submitted data directly to if ($form->isValid()) { // perform some action... - return $this->redirect($this->generateUrl('task_success')); + return $this->redirectToRoute('task_success'); } } @@ -109,7 +109,7 @@ a convenient shortcut to the previous example:: if ($form->isValid()) { // perform some action... - return $this->redirect($this->generateUrl('task_success')); + return $this->redirectToRoute('task_success'); } } diff --git a/cookbook/form/form_collections.rst b/cookbook/form/form_collections.rst index 908523244a2..0ff3284b52f 100644 --- a/cookbook/form/form_collections.rst +++ b/cookbook/form/form_collections.rst @@ -713,7 +713,7 @@ the relationship between the removed ``Tag`` and ``Task`` object. $em->flush(); // redirect back to some edit page - return $this->redirect($this->generateUrl('task_edit', array('id' => $id))); + return $this->redirectToRoute('task_edit', array('id' => $id)); } // render some form template diff --git a/quick_tour/the_controller.rst b/quick_tour/the_controller.rst index 9b1947d29db..3041d90c8c1 100644 --- a/quick_tour/the_controller.rst +++ b/quick_tour/the_controller.rst @@ -74,14 +74,10 @@ requirement. Redirecting and Forwarding -------------------------- -If you want to redirect the user to another page, use the ``redirect()`` +If you want to redirect the user to another page, use the ``redirectToRoute()`` method:: - return $this->redirect($this->generateUrl('_demo_hello', array('name' => 'Lucas'))); - -The ``generateUrl()`` is the same method as the ``path()`` function used in the -templates. It takes the route name and an array of parameters as arguments and -returns the associated friendly URL. + return $this->redirectToRoute('_demo_hello', array('name' => 'Lucas')); You can also internally forward the action to another using the ``forward()`` method:: From 8b2372987674b9f5a0015562428967dafd9cb0aa Mon Sep 17 00:00:00 2001 From: Thomas Royer Date: Tue, 30 Sep 2014 09:23:45 +0200 Subject: [PATCH 5/8] Changed to addFlash where it is possible (ie in controllers) --- book/controller.rst | 6 +----- quick_tour/the_controller.rst | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/book/controller.rst b/book/controller.rst index 87dd1fb5894..525b3b793d3 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -701,7 +701,7 @@ For example, imagine you're processing a form submit:: if ($form->isValid()) { // do some sort of processing - $this->get('session')->getFlashBag()->add( + $this->addFlash( 'notice', 'Your changes were saved!' ); @@ -716,10 +716,6 @@ After processing the request, the controller sets a ``notice`` flash message and then redirects. The name (``notice``) isn't significant - it's just what you're using to identify the type of the message. -.. versionadded:: 2.6 - You can use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::addFlash` - method as a shortcut to ``$this->get('session')->getFlashBag()->add(...)``. - In the template of the next action, the following code could be used to render the ``notice`` message: diff --git a/quick_tour/the_controller.rst b/quick_tour/the_controller.rst index 3041d90c8c1..783810cdf8a 100644 --- a/quick_tour/the_controller.rst +++ b/quick_tour/the_controller.rst @@ -161,7 +161,7 @@ They are useful when you need to set a success message before redirecting the user to another page (which will then show the message):: // store a message for the very next request (in a controller) - $session->getFlashBag()->add('notice', 'Congratulations, your action succeeded!'); + $this->addFlash('notice', 'Congratulations, your action succeeded!'); .. code-block:: html+jinja From 4a54c5fdd38e3ae6e6c156dabec70d7fdd783c6b Mon Sep 17 00:00:00 2001 From: Thomas Royer Date: Tue, 30 Sep 2014 09:29:53 +0200 Subject: [PATCH 6/8] And now the same for isGranted where it is possible --- book/security.rst | 20 ++++---------------- cookbook/security/remember_me.rst | 6 +----- cookbook/security/securing_services.rst | 4 +--- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/book/security.rst b/book/security.rst index f061fa43642..2fbabc3dc90 100644 --- a/book/security.rst +++ b/book/security.rst @@ -1092,9 +1092,7 @@ authorization from inside a controller:: public function helloAction($name) { - if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) { - throw $this->createAccessDeniedException('Unable to access this page!'); - } + $this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page!'); // ... } @@ -1124,12 +1122,6 @@ Thanks to the SensioFrameworkExtraBundle, you can also secure your controller us For more information, see the :doc:`FrameworkExtraBundle documentation `. -.. versionadded:: 2.6 - You can use directly :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::isGranted` - instead of `$this->get('security.context')->isGranted($role)` to check if - a role is granted and :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::denyAccessUnlessGranted` - to throw an exception if the access is not granted (like in the example above). - Securing other Services ~~~~~~~~~~~~~~~~~~~~~~~ @@ -1742,9 +1734,7 @@ authorization from inside a controller:: public function helloAction($name) { - if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ROLE_ADMIN'); // ... } @@ -1772,11 +1762,9 @@ accepts an :class:`Symfony\\Component\\ExpressionLanguage\\Expression` object:: public function indexAction() { - if (!$this->get('security.context')->isGranted(new Expression( + $this->denyAccessUnlessGranted(new Expression( '"ROLE_ADMIN" in roles or (user and user.isSuperAdmin())' - ))) { - throw new AccessDeniedException(); - } + )); // ... } diff --git a/cookbook/security/remember_me.rst b/cookbook/security/remember_me.rst index 7efb39f277d..22b9b0b2372 100644 --- a/cookbook/security/remember_me.rst +++ b/cookbook/security/remember_me.rst @@ -162,11 +162,7 @@ In the following example, the action is only allowed if the user has the public function editAction() { - if (false === $this->get('security.context')->isGranted( - 'IS_AUTHENTICATED_FULLY' - )) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); // ... } diff --git a/cookbook/security/securing_services.rst b/cookbook/security/securing_services.rst index b13a8fbc99b..3bda6fd09aa 100644 --- a/cookbook/security/securing_services.rst +++ b/cookbook/security/securing_services.rst @@ -14,9 +14,7 @@ and checking the current user's role:: public function helloAction($name) { - if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) { - throw new AccessDeniedException(); - } + $this->denyAccessUnlessGranted('ROLE_ADMIN'); // ... } From 6db9c11a166beb83e6a794d68ed4a25a25b5c1cc Mon Sep 17 00:00:00 2001 From: Thomas Royer Date: Sun, 4 Jan 2015 12:17:32 +0100 Subject: [PATCH 7/8] Modifications according to comments --- book/controller.rst | 18 +++++++++++++++++- book/security.rst | 10 ++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/book/controller.rst b/book/controller.rst index b316263ac4c..1c994d31ae2 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -436,6 +436,20 @@ method:: public function indexAction() { return $this->redirectToRoute('homepage'); + + // redirectToRoute is equivalent to using redirect() and generateUrl() together: + // return $this->redirect($this->generateUrl('homepage'), 301); + } + +.. versionadded:: 2.6 + The ``redirectToRoute()`` method was added in Symfony 2.6. Previously (and still now), you + could use ``redirect()`` and ``generateUrl()`` together for this (see the example below). + +Or, if you want to redirect externally, just use ``redirect()`` and pass it the URL:: + + public function indexAction() + { + return $this->redirect('http://symfony.com/doc'); } By default, the ``redirectToRoute()`` method performs a 302 (temporary) redirect. To @@ -448,7 +462,7 @@ perform a 301 (permanent) redirect, modify the second argument:: .. tip:: - The ``redirectToRoute()`` method is simply a shortcut that creates a ``Response`` + The ``redirect()`` method is simply a shortcut that creates a ``Response`` object that specializes in redirecting the user. It's equivalent to:: use Symfony\Component\HttpFoundation\RedirectResponse; @@ -624,6 +638,8 @@ For example, imagine you're processing a form submit:: 'Your changes were saved!' ); + // $this->addFlash is equivalent to $this->get('session')->getFlashBag()->add + return $this->redirectToRoute(...); } diff --git a/book/security.rst b/book/security.rst index 23ced2b773e..4f72e6a2f52 100644 --- a/book/security.rst +++ b/book/security.rst @@ -256,12 +256,22 @@ Protecting your application based on URL patterns is easy, but may not be fine-grained enough in certain cases. When necessary, you can easily force authorization from inside a controller:: +.. versionadded:: 2.6 + The ``denyAccessUnlessGranted()`` method was introduced in Symfony 2.6. Previously (and + still now), you could check access directly and throw the ``AccessDeniedException`` as shown + in the example below). + // ... public function helloAction($name) { $this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page!'); + // Old way : + // if (false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) { + // throw $this->createAccessDeniedException('Unable to access this page!'); + // } + // ... } From 0758d62968b3cfcbfc406004fa7c35971ef0c3fb Mon Sep 17 00:00:00 2001 From: Thomas Royer Date: Sun, 4 Jan 2015 15:49:50 +0100 Subject: [PATCH 8/8] Fixes --- book/security.rst | 11 ++++++----- quick_tour/the_controller.rst | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/book/security.rst b/book/security.rst index 4f72e6a2f52..312bffe5449 100644 --- a/book/security.rst +++ b/book/security.rst @@ -252,21 +252,23 @@ user to be logged in to access this URL: Securing a Controller ~~~~~~~~~~~~~~~~~~~~~ -Protecting your application based on URL patterns is easy, but may not be -fine-grained enough in certain cases. When necessary, you can easily force -authorization from inside a controller:: - .. versionadded:: 2.6 The ``denyAccessUnlessGranted()`` method was introduced in Symfony 2.6. Previously (and still now), you could check access directly and throw the ``AccessDeniedException`` as shown in the example below). +Protecting your application based on URL patterns is easy, but may not be +fine-grained enough in certain cases. When necessary, you can easily force +authorization from inside a controller:: + // ... public function helloAction($name) { $this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page!'); + // The second parameter is used to specify on what object the role is tested. + // // Old way : // if (false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) { // throw $this->createAccessDeniedException('Unable to access this page!'); @@ -322,7 +324,6 @@ to users that have a specific role. array('path' => '^/admin', 'role' => 'ROLE_ADMIN'), ), )); ->>>>>>> master .. note:: diff --git a/quick_tour/the_controller.rst b/quick_tour/the_controller.rst index 12a944f4b6e..e719f921c14 100644 --- a/quick_tour/the_controller.rst +++ b/quick_tour/the_controller.rst @@ -192,7 +192,6 @@ method:: The ``redirectToRoute()`` method takes as arguments the route name and an optional array of parameters and redirects the user to the URL generated with those arguments. ->>>>>>> master You can also internally forward the action to another action of the same or different controller using the ``forward()`` method::