Symfony2,doctrine2,我可以在控制器中返回一个数组作为响应吗?

时间:2014-06-19 22:08:48

标签: symfony controller twig

我有一个嵌入式控制器,它接受一个参数并从db中检索。

{% for key, value in boxes %}
{{ render(controller('ABundle:Reports:getBox', { 'boxnum' : value.boxnum })) }}
<tr>
     <td>{{ value.boxnum }}</td>
     <td>{{ value.boxname }}</td>
     <td>( # of total box )</td>
     <td>( # of available box)</td>
 </tr>
 {% endfor %}

控制器:

public function getBox($boxnum) {
    $em = $this->getDoctrine()->getRepository('ABundle:MainBoxes');
    $getbox = $em->availBoxes($boxnum);

    return new Response(array('getbox' => $getbox)); // this doesn't work obviously...
}

我希望结果检索db并在循环中打印出来。像

这样的东西
<tr>
     <td>{{ value.boxnum }}</td>
     <td>{{ value.boxname }}</td>
     <td>{{ getbox.totalbox }}</td>
     <td>{{ getbox.availbox }}</td>
 </tr>

我收到错误的回复错误。它不允许我返回一个数组?

An exception has been thrown during the rendering of a template ("The Response 
content must be a string or object implementing __toString(), "array" given.")

0 个答案:

没有答案