微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

降级 Twig:未捕获的错误:调用未定义的方法 Twig\Environment

如何解决降级 Twig:未捕获的错误:调用未定义的方法 Twig\Environment

我在一个项目中使用 Symfony 4.4,我需要使用 stfalcontinymce。由于我使用的是 SF4,因此我使用 need 2.4 版。所以我这样做了:

composer require stfalcon/tinymce-bundle=2.4

但后来我收到此错误

!!  11:03:44 CRITICAL  [PHP] Uncaught Error: Class 'Twig_Extension' not found ["exception" => Error { …}]
!!
!!  In StfalconTinymceExtension.PHP line 13:
!!                                                                        
!!    Attempted to load class "Twig_Extension" from the global namespace. 
!!    Did you forget a "use" statement? 

有人告诉我是因为这个版本和Twig 3不兼容所以我需要降级我的Twig版本。然后我这样做是为了降级 Twig:

composer require twig/twig=2

但后来我收到此错误

     13:14:07 CRITICAL  [PHP] Uncaught Error: Call to undefined method Twig\Environment::registerUndefinedTokenPa
rserCallback() ["exception" => Error { …}]
!!
!!  In srcApp_KernelDevDebugContainer.PHP line 2040:
!!  
!!    Attempted to call an undefined method named "registerUndefinedTokenParserCallback" of class "Twig\Environm ent".
!!    Did you mean to call e.g. "registerUndefinedFilterCallback" or "registerUndefinedFunctionCallback"?

我尝试在 composer.json 中添加

"twig/extensions": "*"

然后composer install,然后运行命令:

composer require stfalcon/tinymce-bundle=2.4 -W

我收到此错误

!!  13:49:04 CRITICAL  [PHP] Uncaught Error: Call to undefined method 

Twig\Environment::registerUndefinedTokenParserCallback() ["exception" => Error { …}]
!!
!!  In srcApp_KernelDevDebugContainer.PHP line 2045:
!!  
!!    Attempted to call an undefined method named "registerUndefinedTokenParserCallback" of class "Twig\Environment".
!!    Did you mean to call e.g. "registerUndefinedFilterCallback" or "registerUndefinedFunctionCallback"?

我真的迷路了。有人可以帮忙吗?谢谢

解决方法

您执行的命令在我的系统上似乎根本不可能,因为会存在版本约束冲突。

与其将依赖项限制为一个版本,不如使用约束。

您在 composer.json 中的需求可能包含以下内容

        "twig/twig": "^2","stfalcon/tinymce-bundle": "2.4.*","twig/extra-bundle": "^2"

约束解释document。但 ^2 基本上意味着 >= 2.x.x and < 3.0.0

对于tinymce bundle,我使用了上面的,因为这个here

此外,twig/extensions 似乎已被弃用,GitHub issue 提到 twig/extra-bundle 是需要的,可能是它的替代品。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。