如何使用 security.yml 中的控制器名称来保护特定控制器。
就像是:
access_control:
- { controller: my.controller.name, roles: ROLE_USER }
如何使用 security.yml 中的控制器名称来保护特定控制器。
就像是:
access_control:
- { controller: my.controller.name, roles: ROLE_USER }
public function helloAction($name)
{
// The second parameter is used to specify on what object the role is tested.
$this->denyAccessUnlessGranted('ROLE_USER', null, 'Unable to access this page!');
// Old way :
// if (false === $this->get('security.authorization_checker')->isGranted('ROLE_USER')) {
// throw $this->createAccessDeniedException('Unable to access this page!');
// }
// ...
}