2016-04-16 27 views
0

我爲我的函數添加了@Security(「has_role('ROLE_ADMIN')」)註釋。 當用戶不是admin時,會出現403頁面。 我可以設置重定向到家而不是這個嗎?Symfony3 acess控件重定向

回答

0

不能重定向使用註解,你應該做一個控制器:

if (!$this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) { 
     return $this->redirectToRoute('homepage'); 
    }