如何在symfony 2中访问角色安全上下文令牌?

时间:2013-10-18 10:43:26

标签: php symfony

如何在symfony 2中访问角色安全上下文令牌?

在welcomeAcation

中的Controller文件中的代码
$usernames  = $session->get('usernames');
$password = $session->get('password');
$token = new UsernamePasswordToken($usernames, $password, 'secured_area', array('ROLE_USER','CMS_CONTROL_VIEW','CMS_CONTROL_EDIT','CMS_CONTROL_LIKE'));
$this->get('security.context')->setToken($token);

我在用户中应用了服装角色以及如何在角色中获取twig文件?

我在twig文件中有以下代码 欢迎{{app.security.getToken()}}! 并打印到

UsernamePasswordToken(user="testuser", authenticated=true, roles="CMS_CONTROL_VIEW, CMS_CONTROL_EDIT, CMS_CONTROL_ADD") !

但不要跑下去

{% if is_granted('CMS_CONTROL_EDIT') %}
echo "test";
{% endif %}

如何在twig文件中检查角色?

0 个答案:

没有答案
相关问题