开发者

Twig in syfmony2 returns blank

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 err开发者_如何学JAVAor, 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?


I don't know what's wrong, but this does solve it:

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

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜