syfmony2 中的 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". [] []
我认为第三行一定是问题所在,但我不知道它意味着什么,或者有任何解决方法。
编辑: 如果我改变我的控制器: - 删除了@Template() - end 看起来像:
$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". [] []
就像内核无法返回响应?
My problem is my controller finishes successfully, but twig/view then renders a blank. The request returns no html.
My controller ends fine with:
$logger->info('Now sending song [' . $song->getId() . ' to twig');
return array('song'=>$song);
}
As I have no error, it's difficult to locate the problem. All I have is the dev.log from monolog:
[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". [] []
I think that 3rd line must be the problem, but I don't have a clue what it means, or any means for a resolution.
EDIT:
If I change my controller:
- removed the @Template()
- end looks like:
$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);
Then my dev.log is:
[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". [] []
It's like the kernel just can't return the response?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道出了什么问题,但这确实解决了这个问题:
应该知道这将是缺乏错误报告的原则。无论如何,该表只有 1000 行,所以不确定它对于 twig 的处理来说会太多,特别是因为我只传递一行/实体。
不得不承认我对教义感到失望;或者问题可能出在 symfony 模板的糟糕设计上?
I don't know what's wrong, but this does solve it:
Should've known it would be doctrine with the lack of error reporting. Anyway, the table is only 1000 rows, so not sure how it can be too much for twig too handle, especially since i only pass one row/entity.
Have to admit I'm disappointed with doctrine; or maybe the problem lies with bad design on symfony's templating?