【发布时间】:2012-04-12 08:47:46
【问题描述】:
我只是为模板(index.html.twig)添加:
{{ dump(product) }}
我有错误:
The function "dump" does not exist in AcmeStoreBundle:Default:index.html.twig at line 2
为什么这个功能没有开启,如何开启?
【问题讨论】:
我只是为模板(index.html.twig)添加:
{{ dump(product) }}
我有错误:
The function "dump" does not exist in AcmeStoreBundle:Default:index.html.twig at line 2
为什么这个功能没有开启,如何开启?
【问题讨论】:
你需要to configure调试扩展:
# app/config/config.yml
services:
acme_hello.twig.extension.debug:
class: Twig_Extension_Debug
tags:
- { name: 'twig.extension' }
根据上面提到的链接,Twig 调试默认设置为在运行 Twig 1.16+ 的 Symfony 2.5+ 中工作,并且不需要自定义服务定义。 See this answer for more details.
【讨论】:
twig: debug: true
composer update(从 Twig 1.15 升级到 1.16,现在它正在工作。所以谁知道......
当你像@meze 说的那样配置它时,你可以显示所有自定义变量:
<h1>Variables passed to the view:</h1>
{% for key, value in _context %}
{% if key starts with '_' %}
{% else %}
<pre style="background: #eee">{{ key }}</pre>
{{ dump(value) }}
{% endif %}
{% endfor %}
您可以使用我的简单插件来方便地检查您的变量:
【讨论】:
Symfony 2.7+ 更新:
DebugBundle 允许将组件更好地集成到 Symfony 全栈框架中。它在 Symfony 标准版的开发和测试环境中默认启用。
检查VarDumper component 及其integration on Twig。
老答案:
我想建议一个非本地解决方案。您需要第三方捆绑包,但最终结果会很棒!
dump 版本的改进:
ldd(),这是经典“转储死”的别名php app/console ladybug:dump "Symfony\Component\HttpFoundation\Request")这里是链接:
【讨论】:
VarDumper 组件:symfony.com/doc/current/components/…