0

如何使用 security.yml 中的控制器名称来保护特定控制器。

就像是:

access_control:
    - { controller: my.controller.name, roles: ROLE_USER }
4

1 回答 1

0
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!');
    // }

    // ...
}
于 2016-06-05T15:35:56.050 回答