更新时间:2023-02-26 08:36:34
VIEW是权限,而不是角色。
The "VIEW" is a permission, not a role.
检查用户是否具有权限(角色或权限)的***方法是访问AccessDecisionManager。
The best way to check if a user has a right (be it a role or permission) would be to access the AccessDecisionManager. Something like:
$token = new UsernamePasswordToken($user, 'none', 'none', $user->getRoles());
$attributes = is_array($attributes) ? $attributes : array($attributes);
$this->get('security.access.decision_manager')->decide($token, $attributes, $object);
在此处查看原始答案:https://***.com/a/22380765/971254 了解详情。
See original answer here: https://***.com/a/22380765/971254 for details.