0
Q
重定向匿名用户/
A
回答
0
首先,检查if the user is authorized。然后,使用if条件来重定向用户。索引的
完整的示例:
public function indexAction()
{
$context = $this->container->get('security.authorization_checker');
if (!($context->isGranted('IS_AUTHENTICATED_REMEMBERED'))) {
$this->redirect('http://yourpage.com/login');
} else {
//Do your other stuff here
}
}
1
使用防火墙来保护/
:
# app/config/security.yml
security:
firewalls:
app:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ROLE_ADMIN }
更多细节在FOSUserBundle docs。
这就是我的security.yml现在的样子,但它不适用于我,我不知道为什么 –
您是否遵循FOSUserBundle指南?激活捆绑等 – Jonny
是的。一切工作完美,除了它 –