3

How can i know the roles of my personel.

$personal = $em->getRepository('AuthenticationBundle:User')->FindPersonel($id);    

dump($personal->getRoles());
die();

there is nothing blank page.

nasri_thamer
  • 109
  • 1
  • 15
  • not the current user i have selected a personal from my DB i want to see his roles .. – nasri_thamer Apr 28 '16 at 17:12
  • there is no error when i dow the dump($personal); i saw the personal and in twig i do the for role in personal.roles its ok.. my question how to do it in controller – nasri_thamer Apr 28 '16 at 17:23
  • you can test it there is in php – nasri_thamer Apr 28 '16 at 17:27
  • the dump function is in symfony2 use Symfony\Component\VarDumper\VarDumper; if (!function_exists('dump')) { /** * @author Nicolas Grekas

    */ function dump($var) { foreach (func_get_args() as $var) { VarDumper::dump($var); } } }

    – nasri_thamer Apr 28 '16 at 17:32
  • `\Doctrine\Common\Util\Debug::dump($personal);` might be of use. – ccKep Apr 28 '16 at 21:29

2 Answers2

8
if(in_array('ROLE_ADMIN', $this->getUser()->getRoles())){
   //Is ADMIN !!!         
}
Zarpele
  • 513
  • 1
  • 6
  • 10
1
    foreach( $personal->getRoles() as $role){
        echo $role;
    }
    die();

we must loop the getRoles()

nasri_thamer
  • 109
  • 1
  • 15