如何在我的行动中获得用户角色

Abd*_*z24 1 zend-framework2 zfcuser bjyauthorize

我使用zf2与这两个模块(zfc-user,bjyauthorize),我想从我的行动中获取用户角色

Rem*_*mas 11

试试这个

在你的控制器中

$viewmodel = new ViewModel();
$authorize = $this->getServiceLocator()->get('BjyAuthorize\Provider\Identity\ProviderInterface');
$roles = $authorize->getIdentityRoles();

$viewmodel->setVariable("roles", $roles);
return $viewmodel;
Run Code Online (Sandbox Code Playgroud)

在您的视图脚本中

<?php var_dump($this->roles); ?>
Run Code Online (Sandbox Code Playgroud)