【问题标题】:How do I get the entity that represents the current user on a PHP template?如何在 PHP 模板上获取代表当前用户的实体?
【发布时间】:2013-07-31 16:43:34
【问题描述】:

正如在这个问题How do I get the entity that represents the current user in Symfony2? 上回答的那样,这向您展示了如何在控制器上执行此操作,但是您如何在 php 模板上获取实际用户实体而无需将其发送到模板的参数上?

据我所知:

$app->getSession()->getUsername();

但这只是给出了一个带有用户名的原始变量,我想要 用户实体

【问题讨论】:

标签: php symfony


【解决方案1】:

你可以在php模板中使用$app->getUser(),在twig模板中使用app.user

见:http://symfony.com/doc/current/book/security.html

【讨论】:

    猜你喜欢
    • 2011-12-02
    • 2016-09-25
    • 2015-03-13
    • 2013-01-26
    • 2014-02-27
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 2011-02-22
    相关资源
    最近更新 更多