Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

4668 document isCsrfTokenValid#5325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
snoek09 wants to merge4 commits intosymfony:2.6fromsnoek09:4668-document-is-csrf-token-valid
Closed
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletionbook/controller.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -440,7 +440,7 @@ If you want to redirect the user to another page, use the ``redirectToRoute()``
}

.. versionadded:: 2.6
The ``redirectToRoute()`` method wasadded in Symfony 2.6. Previously (and still now), you
The ``redirectToRoute()`` method wasintroduced in Symfony 2.6. Previously (and still now), you
could use ``redirect()`` and ``generateUrl()`` together for this (see the example above).

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

Checking the Validity of a CSRF Token
-------------------------------------

Sometimes you want to use CSRF protection in an action where you don't want to use a
Symfony form.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think "[...] to use the Symfony Form component." is better


If, for example, you're doing a DELETE action, you can use the
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::isCsrfTokenValid`
method to check the CSRF token::

if ($this->isCsrfTokenValid('token_id', $submittedToken)) {
// ... do something, like deleting an object
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For consistency with other parts of the doc, there should be a comment showing the alternative not using the shortcut


.. versionadded:: 2.6
The ``isCsrfTokenValid()`` shortcut method was introduced in Symfony 2.6.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I prefer something like this:

..versionadded::2.6    The ``isCsrfTokenValid()`` shortcut method was introduced in Symfony 2.6.    It is equivalent to executing the following code::        use Symfony\Component\Security\Csrf\CsrfToken;        $this->get('security.csrf.token_manager')->isTokenValid(new CsrfToken('token_id', 'TOKEN'));


Previously you would use::

use Symfony\Component\Security\Csrf\CsrfToken;

$this->get('security.csrf.token_manager')->isTokenValid(new CsrfToken('token_id', 'TOKEN'));

Final Thoughts
--------------

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp