【问题标题】:Downgrading Twig: Uncaught Error: Call to undefined method Twig\Environment降级 Twig:未捕获的错误:调用未定义的方法 Twig\Environment
【发布时间】:2021-04-12 05:57:12
【问题描述】:

我在一个项目中使用 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 和 lock 文件。这让我们可以准确地看到安装了哪些库
  • 相关帖子中的信息可能是问题所在。在github上看到这个问题线程github.com/symfony/symfony/issues/39734也许你需要指定twig/extra-bundle的版本
  • 我在发布我的问题之前已经看到了这个问题,但它并没有解决我的问题。
  • 作为提示:您不应该完全安装 v2.4 - 有一个 2.4.1 版本修复了一些错误。最好使用适当的版本约束,例如 ^2.4

标签: php symfony twig composer-php downgrade


【解决方案1】:

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

您应该使用约束,而不是将依赖项限制为一个版本。

composer.json 中的要求可能包含以下内容

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

约束在here 中进行了解释。但是^2 基本上意味着>= 2.x.x and < 3.0.0

由于GitHub issue,我使用上面的tinymce包

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

【讨论】:

  • 谢谢它的工作。我对各种版本的依赖项感到困惑并且迷路了。我会记住不要限制我的依赖项的版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-21
  • 2017-06-11
相关资源
最近更新 更多