4

as per the documentation:

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

I am trying to use twig to check to see if the user is authenticated

when i put in my twig templates:

{{ app.user.username }}

I get the error

LogicException: Unable to add global "app" as the runtime or the extensions have already been initialized.

EDIT: Please find as per below the composer.json contents

{
    "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"
    }
}
2
  • 1
    I would update your vendors and clear your cache. Something is wonky. AFAIK, the only way that can happen is if you have a Twig Extension and you used addGlobal('app', 'some value'); Jan 11, 2013 at 17:57
  • Are you using such a non-Sensiolab bundle? Which version do you use exactly? Can you post your composer.json? Jan 12, 2013 at 13:42

1 Answer 1

1

Its hard to answer to this question without more details.

First, please notice that there have been such a similar exception in the past, due to a Symfony2.1 bug which has been solved with a recent release: see here for more details.

Then, notice that the error seems to be thrown in addGlobal function of class Twig_Environment. Did you installed such Twig Extension?

Without reading your composer.json, I can suggest to try to:

  1. Clear the cache.
  2. update the code in your composer.json, to avoid the presence of up to date bundles.
  3. Create the composer.phar.
  4. Then compile it to get the composer.phar.
  5. php composer.phar install or php composer.phar update, whatever be your case.

Hope it helps.

2
  • The Composer.json is correct! Do you generate the composer.phar through the latest version of Composer? Does the update and the clearing of the cache helped? Jan 14, 2013 at 13:19
  • Here you can find a similar issue. Jan 14, 2013 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.