3

我现在有点困惑。我总是像使用任何其他 twig 函数一样使用 twig dump 函数,但现在它绝对没有输出。没有错误/异常,什么都没有。其他一切正常,例如反式过滤器。

{{ dump('test') }} # prints nothing
{{ 'layout.booking.chooseArea'|trans }} # prints the translated message

现在这个模板不包含任何其他内容。转储在父模板或 base.html.twig 中也不起作用。

同样,转储不打印任何内容:不是空字符串,不是 null,也不是屏幕上的单个像素。

有什么想法可能导致这种情况吗?

Symfony 版本:2.6.x-dev

更新

{{ dump('test') }} # doesn't work (anymore?)
{% dump('test') %} # does (still) work

这是被删除还是什么?为什么没有错误?顺便说一句...调试标志已设置。

4

1 回答 1

5

In Symfony 2.6, there is a new VarDumper component and DebugBundle. These override twig's dump() function to give a lot more and nicer dump output.

However, you have to register the DebugBundle in your AppKernel, otherwise it'll just ignore the call. To do this, you should add this to app/AppKernel.php:

// app/AppKernel.php

// ...
public function registerBundles()
{
    // ...

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        // ...
    }

    return $bundles;
}

Please note that this new dump function will dump the output in the web dev toolbar, to avoid screwing up the page layout.

In 2.6.0, this will be fixed by having a fallback to the native twig dump() function why the DebugBundle is not registered.

于 2014-11-14T00:47:06.553 回答