Skip to content

Commit 7c8d5d2

Browse files
committed
minor #5816 Merge branches (nicolas-grekas, snoek09, WouterJ, xabbuh)
This PR was merged into the 2.7 branch. Discussion ---------- Merge branches | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.7+ | Fixed tickets | Merges some commits that have been done in the `2.6` branch after we stopped support for that version. Commits ------- ab19cfb fix code block syntax 0ed7d99 Merge remote-tracking branch 'upstream/2.6' into merge-branches 149576e feature #5310 Fix missing note about debug.dump_destination (nicolas-grekas) f67c353 [#5572] Fix syntax 85dc294 feature #5572 4668 document isCsrfTokenValid (snoek09) 11383f8 4668 document isCsrfTokenValid dae2811 Fix missing note about debug.dump_destination
2 parents 5494f15 + ab19cfb commit 7c8d5d2

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

book/controller.rst

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ If you want to redirect the user to another page, use the ``redirectToRoute()``
440440
}
441441

442442
.. 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
444444
could use ``redirect()`` and ``generateUrl()`` together for this (see the example above).
445445

446446
Or, if you want to redirect externally, just use ``redirect()`` and pass it the URL::
@@ -811,6 +811,29 @@ Just like when creating a controller for a route, the order of the arguments of
811811
order of the arguments, Symfony will still pass the correct value to each
812812
variable.
813813

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+
.. code-block:: php
831+
832+
use Symfony\Component\Security\Csrf\CsrfToken;
833+
834+
$this->get('security.csrf.token_manager')
835+
->isTokenValid(new CsrfToken('token_id', 'TOKEN'));
836+
814837
Final Thoughts
815838
--------------
816839

0 commit comments

Comments
 (0)