Skip to content

Clarify comment about "Retrieving the User Object" #8542

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all 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
16 changes: 6 additions & 10 deletions security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -999,14 +999,12 @@ look like::

use Symfony\Component\Security\Core\User\UserInterface;

public function indexAction(UserInterface $user)
public function indexAction()
{
if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
throw $this->createAccessDeniedException();
}
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');

// the above is a shortcut for this
$user = $this->get('security.token_storage')->getToken()->getUser();
$user = $this->getUser();
// or you can also type-hint a method argument with UserInterface: e.g. "UserInterface $user"
}

.. tip::
Expand All @@ -1015,10 +1013,8 @@ look like::
your :ref:`user provider <security-user-providers>`.

.. versionadded:: 3.2
The functionality to get the user via the method signature was introduced in
Symfony 3.2. You can still retrieve it by calling ``$this->getUser()`` if you
extend the :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller`
class.
The ability to get the user by type-hinting an argument with UserInterface
was introduced in Symfony 3.2.

Now you can call whatever methods are on *your* User object. For example,
if your User object has a ``getFirstName()`` method, you could use that::
Expand Down