gpt4 book ai didi

authentication - Twig 中的 app.user.username 返回无法添加全局

转载 作者:行者123 更新时间:2023-12-01 05:25:09 26 4
gpt4 key购买 nike

根据文档:

http://symfony.com/doc/current/book/security.html#retrieving-the-user-object

我正在尝试使用 twig 检查用户是否通过身份验证

当我放入 Twig 模板时:
{{ app.user.username }}

我收到错误
LogicException: Unable to add global "app" as the runtime or the extensions have already been initialized.

编辑:请按照下面的 composer.json 内容查找
{
"name": "symfony/framework-standard-edition",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.0.*",
"twig/extensions": "1.0.*@dev",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
"symfony/monolog-bundle": "2.1.*",
"sensio/distribution-bundle": "2.1.*",
"sensio/framework-extra-bundle": "2.1.*",
"sensio/generator-bundle": "2.1.*",
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"kriswallsmith/assetic": "1.1.*@dev",
"doctrine/data-fixtures": "dev-master",
"doctrine/doctrine-fixtures-bundle": "dev-master"
},
"scripts": {
"post-install-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web"
}
}

最佳答案

如果没有更多细节,很难回答这个问题。

首先,请注意过去也有过类似的异常,由于 Symfony2.1最近版本已解决的错误:see here for more details .

然后,请注意错误似乎是在 addGlobal 中抛出的。类的函数Twig_Environment .你安装了这样的 Twig Extension 吗?

没有阅读您的 composer.json ,我可以建议尝试:

  • 清除缓存。
  • 更新 您的 composer.json 中的代码, 以避免出现最新的包。
  • 创建 composer.phar .
  • 然后编译得到composer.phar .
  • php composer.phar installphp composer.phar update ,不管你是什么情况。

  • 希望能帮助到你。

    关于authentication - Twig 中的 app.user.username 返回无法添加全局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14282842/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com