나는 'ROLE_ADMIN'역할을 가진 사용자 Adam이라고 가정 할 수 있습니다. 프론트 엔드에 로그인 할 수 없습니다.
if($this->get('security.context')->isGranted('ROLE_ADMIN'))
return new Response('You are granted to see this site.');
:이 코드를 추가해야합니다 당신이 BackendController을 보호하려면, 그래서
if($this->get('security.context')->isGranted('YOUR ROLE'))
return new Response('yea!');
과 'ROLE_ADMIN'사용자에게 로그인 보자
당신은 간단하게 당신의 컨트롤러에이 코드를 추가해야합니다
이 코드는 현재 사용자 (나)가 ROLE_ADMIN 역할을 가지고 있는지 확인합니다. 당신은 사용자가 'ROLE_USER을'이없는 및을 'ROLE_ADMIN'를 가지고 있는지 확인하려면 단지 추가 :
$security = $this->get('security.context');
if($security->isGranted('ROLE_ADMIN') && !$security->isGranted('ROLE_USER'))
return new Response('You are not granted to see this site.');