且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查是否在Symfony2 ACL中为特定用户授予了角色

更新时间: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.