@@ -440,7 +440,7 @@ If you want to redirect the user to another page, use the ``redirectToRoute()``
440
440
}
441
441
442
442
.. versionadded :: 2.6
443
- The ``redirectToRoute() `` method was added in Symfony 2.6. Previously (and still now), you
443
+ The ``redirectToRoute() `` method was introduced in Symfony 2.6. Previously (and still now), you
444
444
could use ``redirect() `` and ``generateUrl() `` together for this (see the example above).
445
445
446
446
Or, if you want to redirect externally, just use ``redirect() `` and pass it the URL::
@@ -811,6 +811,27 @@ Just like when creating a controller for a route, the order of the arguments of
811
811
order of the arguments, Symfony will still pass the correct value to each
812
812
variable.
813
813
814
+ Validating a CSRF Token
815
+ -----------------------
816
+
817
+ Sometimes, you want to use CSRF protection in an action where you don't want to
818
+ use the Symfony Form component. If, for example, you're doing a DELETE action,
819
+ you can use the :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::isCsrfTokenValid `
820
+ method to check the CSRF token::
821
+
822
+ if ($this->isCsrfTokenValid('token_id', $submittedToken)) {
823
+ // ... do something, like deleting an object
824
+ }
825
+
826
+ .. versionadded :: 2.6
827
+ The ``isCsrfTokenValid() `` shortcut method was introduced in Symfony 2.6.
828
+ It is equivalent to executing the following code::
829
+
830
+ use Symfony\Component\Security\Csrf\CsrfToken;
831
+
832
+ $this->get('security.csrf.token_manager')
833
+ ->isTokenValid(new CsrfToken('token_id', 'TOKEN'));
834
+
814
835
Final Thoughts
815
836
--------------
816
837
0 commit comments