4

根据文档:

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

我正在尝试使用 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"
    }
}
4

1 回答 1

1

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

首先,请注意过去也有过类似的异常,这是由于Symfony2.1最近版本已解决的一个错误:请参阅此处了解更多详细信息

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

如果不阅读您的composer.json,我可以建议尝试:

  1. 清除缓存。
  2. 更新, 中的代码composer.json以避免出现最新的捆绑包。
  3. 创建composer.phar.
  4. 然后编译得到composer.phar.
  5. php composer.phar install或者php composer.phar update,无论您的情况如何。

希望能帮助到你。

于 2013-01-12T14:01:06.160 回答