Error “Class 'Twig_SimpleFunction' not found” after upgrade to Symfony 2.2

流过昼夜 提交于 2019-12-11 13:45:55

问题


I recently updated Symfony from 2.1 to 2.2 and now I'm getting error:

Error: Class 'Twig_SimpleFunction' not found in vendor/symfony/symfony/src/Symfony/Bundle/SecurityBundle/Twig/Extension/LogoutUrlExtension.php line 41

My composer.json:

...
"require": {
    "php": ">=5.4",
    "symfony/symfony": "2.2.*",
    "twig/twig": "1.11.x",
    "twig/extensions": "1.0.x-dev",
    "noetix/easy-csv": "dev-master",
    "symfony/assetic-bundle": "2.*",
    "symfony/swiftmailer-bundle": "2.*",
    "symfony/monolog-bundle": "2.*",
    "sensio/distribution-bundle": "2.*",
    "sensio/framework-extra-bundle": "2.*",
    "sensio/generator-bundle": "2.*",
    "jms/security-extra-bundle": "1.4.*",
    "jms/di-extra-bundle": "1.3.*",
    "jms/serializer": "0.12.*",
    "jms/serializer-bundle" : "0.12.*@dev",
    "jms/metadata" : "1.3.*",
    "friendsofsymfony/user-bundle": "patch-1-dev",
    "friendsofsymfony/jsrouting-bundle": "1.2.*",
    "propel/propel1": ">=1.6.7",
    "propel/propel-bundle": "1.2.x-dev",
    "willdurand/propel-typehintable-behavior": "dev-master",
    "pagerfanta/pagerfanta": "1.0.x-dev",
    "white-october/pagerfanta-bundle": "dev-master",
    "knplabs/knp-menu-bundle": "dev-master",
    "knplabs/knp-menu": "2.0.x-dev",
    "exercise/elastica-bundle": "dev-master",
    "gregwar/captcha-bundle": "dev-master",
    "nelmio/api-doc-bundle": "2.1.*",
    "fr3d/ldap-bundle": "2.0.*@dev",
    "conjecto/easyrdf-bundle": "dev-master"
},
...

Twig deprecated features page says: "As of Twig 1.x, use Twig_SimpleFunction". I have 1.11, so I don't get it what I'm doing wrong.


回答1:


Found it. The problem was in invalid dependencies as I suspected. I downloaded Symfony2.2.11 and changed my composer.json accordingly (notice no reference to twig anymore, and changed some symfony/* and sensio/* dependencies):

"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "2.2.*",
    "twig/extensions": "1.0.*",
    "noetix/easy-csv": "dev-master",
    "symfony/assetic-bundle": "2.1.*",
    "symfony/swiftmailer-bundle": "2.2.*",
    "symfony/monolog-bundle": "2.2.*",
    "sensio/distribution-bundle": "2.2.*",
    "sensio/framework-extra-bundle": "2.2.*",
    "sensio/generator-bundle": "2.2.*",
    "jms/security-extra-bundle": "1.4.*",
    "jms/di-extra-bundle": "1.3.*",
    "jms/serializer": "0.12.*",
    "jms/serializer-bundle" : "0.12.*@dev",
    "jms/metadata" : "1.3.*",
    "friendsofsymfony/user-bundle": "patch-1-dev",
    "friendsofsymfony/jsrouting-bundle": "1.2.*",
    "propel/propel1": ">=1.6.7",
    "propel/propel-bundle": "1.2.x-dev",
    "willdurand/propel-typehintable-behavior": "dev-master",
    "pagerfanta/pagerfanta": "1.0.x-dev",
    "white-october/pagerfanta-bundle": "dev-master",
    "knplabs/knp-menu-bundle": "dev-master",
    "knplabs/knp-menu": "2.0.x-dev",
    "exercise/elastica-bundle": "dev-master",
    "gregwar/captcha-bundle": "dev-master",
    "nelmio/api-doc-bundle": "2.1.*",
    "fr3d/ldap-bundle": "2.0.*@dev",
    "conjecto/easyrdf-bundle": "dev-master"
},

This installed twig 1.15 and everything works. The manual page has error - Twig_SimpleFunction appears somewhere between >1.11 and <=1.15, not in 1.x.




回答2:


Twig extension classes are not namespaced. Have you checked that you haven't changed that?

Within you extension class you should use \Twig_SimpleFunction, not just Twig_SimpleFunction



来源:https://stackoverflow.com/questions/20549729/error-class-twig-simplefunction-not-found-after-upgrade-to-symfony-2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!