Created
November 8, 2016 22:28
-
-
Save KhanMaytok/8b641c82755f0751d5649a668bddd6b1 to your computer and use it in GitHub Desktop.
New Symfony way for get logged user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Symfony 2.5 | |
$user = $this->get('security.context')->getToken()->getUser(); | |
// Symfony 2.6 | |
$user = $this->get('security.token_storage')->getToken()->getUser(); | |
// Symfony 2.5 | |
if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) { ... } | |
// Symfony 2.6 | |
if (false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) { ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment