0

我目前在 AdminController.php 工作,我需要检查登录用户的角色。在 FOSUserBundle 的 UserInterface.php 中,我找到了 public 函数hasRole(),这正是我需要的。但在评论中据说永远不会使用该功能。相反,作者建议使用$authorizationChecker->isGranted('ROLE_USER');但我必须调用 isGranted 吗?有没有像 $this->getUser() 这样返回某事的方法。AuthorizationChecker 类型的?

这是完美的工作: $this->getUser()->hasRole('ROLE_ADMIN')

4

0 回答 0