我不知道为什么它会显示这个错误
The function "dump" does not exist in twig file虽然我已经在config.yml文件中写入:
services:
product_store.twig.extension.debug:
class: Twig_Extension_Debug
tags:
- { name: 'twig.extension' }在twig文件中,我尝试使用以下命令进行转储:
{{ dump(product) }}发布于 2013-05-26 02:08:55
后进先出的答案鼓励您使用debug标记,但是debug标记{% debug product %}在Twig1.5中已被弃用,取而代之的是dump函数{{ dump(product) }}。
从Symfony Standard Edition 2.0.9开始,要启用的正确扩展是Twig_Extension_Debug,并且应该添加到app/config/config_dev.yml中,以便它只在开发环境中加载:
services:
twig.extension.debug:
class: Twig_Extension_Debug
tags: [{ name: 'twig.extension' }]然后,您应该能够在模板中使用{{ dump(product) }}。
如果问题仍然存在,您可以尝试几种方法:
php app/console container:debug twig.extension.debug --env=dev来确保依赖注入容器正确地提取您的服务定义。服务的容器信息twig.extension.debug服务Id twig.extension.debug类Twig_Extension_Debug标记- twig.extension ()作用域容器公共是合成的否所需的文件-
Twig_Extension_Debug以查看是否已定义任何其他服务来使用它。此文件位于app/cache/dev/appDevDebugProjectContainer.php
%kernel.debug%为true。
发布于 2012-11-27 21:44:59
首先,"dump“实际上不是命令,而是它的"debug”。其次,您的配置语法有点混乱。它应该看起来像这样:
services:
twig.extension.debug:
class: Twig_Extensions_Extension_Debug
tags:
- { name: twig.extension }然后你可以像这样在你的模板中使用它:{% debug var %} -- 注意{%%}大括号。Debug不能在{{}}大括号内工作,因为它是一个标签而不是一个函数。
发布于 2012-11-06 23:44:08
这可能是因为:
你把它放在哪里了
services:
product_store.twig.extension.debug:
class: Twig_Extension_Debug
tags:
- { name: 'twig.extension' }它应该在您的绑定的config.yml中:
nameOfTheBoundle/Resources/config/config.yml而不是在项目的config.yml中:
app/config/config.ymlhttps://stackoverflow.com/questions/12159373
复制相似问题