在 Symfony 2 中将数组列表发送到没有 headers 的 Twig View

Send array list to Twig View without headers in Symfony 2

我需要帮助在没有 headers 的情况下将查询列表发送到 Twig。我已经查询了我的数据,但我被卡住了。我必须在 JSON 结构中包含这些数据。

这是我的根名称:'AdminBundle:Note:viewPdf.html.twig' 这是 propel 中的查询名称 class - 现在是空的:MnNoteCommentQuery.

这是我的代码:

$noteQuery = MnNoteCommentQuery::create()->find();
$responsed = new JSonResponse($noteQuery);
return $this->render('AdminBundle:Note:viewPdf.html.twig', array('notes' => $responsed));

只需在 twig

中使用 json_encode
return $this->render('AdminBundle:Note:viewPdf.html.twig', array('notes' => $notes));

树枝:

{{ notes | json_encode() }}

您可以通过实现 JsonSerializable 接口自定义 json 表示