Symfony2.7 Twig 如何获取token?
Symfony2.7 Twig How to obtain a token?
在 Twig 文件中我有这个代码:
{% set player = app.security.getToken().getUser().getPlayer() %}
{% if player.getSelectedCharacter() is not null %}
{% set character = player.getSelectedCharacter() %}
{% .... %}
{% endif %}
但现在 app.security
已弃用。所以我想改变这个。我可以在我的控制器中获取用户令牌并将其发送到 Twig。但我更喜欢直接通过 Twig 获取它。
我该怎么做?
正如您在 documentation 中所说和提到的那样。
The app.security global is deprecated as of 2.6. The user is already
available as app.user and is_granted() is registered as function.
我想你可以在你看来尝试这样的事情。
app.user.getPlayer()
在 Twig 文件中我有这个代码:
{% set player = app.security.getToken().getUser().getPlayer() %}
{% if player.getSelectedCharacter() is not null %}
{% set character = player.getSelectedCharacter() %}
{% .... %}
{% endif %}
但现在 app.security
已弃用。所以我想改变这个。我可以在我的控制器中获取用户令牌并将其发送到 Twig。但我更喜欢直接通过 Twig 获取它。
我该怎么做?
正如您在 documentation 中所说和提到的那样。
The app.security global is deprecated as of 2.6. The user is already available as app.user and is_granted() is registered as function.
我想你可以在你看来尝试这样的事情。
app.user.getPlayer()