Skip to content

Instantly share code, notes, and snippets.

@KhanMaytok
Created November 8, 2016 22:28
Show Gist options
  • Save KhanMaytok/8b641c82755f0751d5649a668bddd6b1 to your computer and use it in GitHub Desktop.
Save KhanMaytok/8b641c82755f0751d5649a668bddd6b1 to your computer and use it in GitHub Desktop.
New Symfony way for get logged user
<?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