dongliyu3278 2014-11-07 19:37
浏览 46
已采纳

如何使用Zend框架2获得用户角色?

I am using Zend Framework 2 and having trouble getting the user role. I am using zfc user and Zfc Rbac. The roles currently work however I would like to get the values to use in an if statement (in the controller). What is the function to call these? I have the developer tool turned on so I can see the role assigned but can't figure out out to call it.

Thanks Matt

  • 写回答

2条回答 默认 最新

  • doupi7619 2014-11-10 03:04
    关注

    I was used the below code and was able to get the role of the logged in user.

     $viewmodel = new ViewModel();
     $authorize = $this->getServiceLocator()->get('UserRbac\Identity\IdentityRoleProvider');
     $roles = $authorize->getIdentityRoles();
     echo $roles[0];
        $viewmodel->setVariable("roles", $roles);
    return $viewmodel;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?