symfony2中的twig返回空白

时间:2011-10-04 05:43:30

标签: doctrine-orm symfony twig

我的问题是我的控制器成功完成,但树枝/视图然后呈现空白。请求不返回html。

我的控制器以:

结束
    $logger->info('Now sending song [' . $song->getId() . ' to twig');
    return array('song'=>$song);
}

由于我没有错误,很难找到问题所在。我所拥有的只是来自monolog的dev.log:

[2011-10-04 07:41:03] app.INFO: Now sending song [672] to twig [] []
[2011-10-04 07:41:03] event.DEBUG: Notified event "kernel.view" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelView". [] []
[2011-10-04 07:41:03] event.DEBUG: Listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelView" stopped propagation of the event "kernel.view". [] []
[2011-10-04 07:41:03] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
[2011-10-04 07:41:03] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\SecurityBundle\EventListener\ResponseListener::onKernelResponse". [] []
[2011-10-04 07:41:03] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
[2011-10-04 07:41:03] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
[2011-10-04 07:41:03] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
[2011-10-04 07:41:03] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []

我认为第3行必定是问题,但我不知道它意味着什么,或任何解决方法。

编辑: 如果我改变我的控制器: - 删除了@Template() - 结束看起来像:

$logger->info('Now sending song [' . $song->getId() . '] to twig');
$content = $this->renderView('MyPadBundle:Play:index.html.twig', array('song'=>$song));
$logger->info('content rendered');
return new Response($content);

然后我的dev.log是:

[2011-10-04 09:42:52] app.INFO: Now sending song [189] to twig [] []
[2011-10-04 09:42:53] app.INFO: content rendered [] []
[2011-10-04 09:42:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
[2011-10-04 09:42:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\SecurityBundle\EventListener\ResponseListener::onKernelResponse". [] []
[2011-10-04 09:42:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
[2011-10-04 09:42:53] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
[2011-10-04 09:42:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
[2011-10-04 09:42:53] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []

就像内核只是无法返回响应?

1 个答案:

答案 0 :(得分:1)

我不知道什么是错的,但这确实解决了它:

$logger->info('Now sending song [' . $song->getId() . '] to twig');
$em->clear();
return array('song'=>$song);

如果缺乏错误报告,应该知道它会是学说。无论如何,这个表只有1000行,所以不确定它对于twig太多的处理也是如此,特别是因为我只传递了一行/实体。

不得不承认我对学说感到失望;或者问题可能在于symfony的模板设计不好?