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まず、最近のリリースで解決されたバグのために、過去にそのような同様の例外があったことに注意してください。詳細については、ここを参照してください

addGlobal次に、クラスの関数でエラーがスローされているように見えることに注意してくださいTwig_Environment。そのようなTwigExtensionをインストールしましたか?

あなたを読まずに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 に答える