2013-01-11 51 views
4

按照文檔:app.user.username在樹枝返回不能添加全局

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

我試圖用樹枝進行檢查,看是否該用戶進行身份驗證

,當我把在我的樹枝模板:

{{ 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" 
    } 
} 
+1

我會更新您的供應商並清除您的緩存。有些東西是不可靠的。 AFAIK,可能發生的唯一方法是,如果你有一個Twig Extension,並且你使用了'addGlobal('app','some value');' – phpisuber01

+0

你是否在使用這種非Sensiolab捆綁包?你準確使用哪個版本?你可以發佈你的composer.json嗎? – JeanValjean

回答

1

它很難回答這個問題,沒有更詳細的介紹。

首先,請注意,由於Symfony2.1錯誤已在最近的版本中解決,因此過去也有類似的例外:see here for more details

然後,請注意,該錯誤似乎在addGlobalTwig_Environment函數中拋出。你是否安裝了這種枝條延伸?

不讀你的composer.json,我可以建議嘗試:

  1. 清除緩存。
  2. 更新您的composer.json中的代碼,以避免出現最新的捆綁包。
  3. 創建composer.phar
  4. 然後編譯它得到composer.phar
  5. php composer.phar installphp composer.phar update,無論是你的情況。

希望它有幫助。

+0

新增作曲內容 –

+0

Composer.json是正確的!你是否通過最新版本的Composer生成了composer.phar?更新和清除緩存是否有幫助? – JeanValjean

+0

[Here](http://share.ez.no/forums/ez-publish-5-forum-formerly-known-as-new-php-api/twig-fails)你可以找到類似的問題。 – JeanValjean