我在渲染Twig视图和JSON响应时遇到问题,我需要调用twig视图并将一个新的Json响应作为参数传递给它。输出错误如下:“通知: Symfony\Component\HttpFoundation\Response类的对象无法转换为int”以下是代码
$resultado = array('mes1_local' => $mes1_local, 'mes2_local' => $mes2_local, 'mes3_local' => $mes3_local, 'mes1_online' => $mes1_online, 'mes2_online' => $mes2_online, 'mes3_online' => $mes3_online, 'contador_pedido_local' => $contador_pedido_local, 'contador_pedido_online' => $contador_pedido_online, 'contador_total' => $contador_total, 'contador_usuarios' => $contador_usuarios);
return new JsonResponse($resultado, $this->render('others/adminlte.html.twig'));
发布于 2018-02-21 15:45:47
Json响应签名是
__construct(mixed $data = null, int $status = 200, array $headers = array(), bool $json = false)
您正在尝试将小枝传递给status参数。
您可以使用一个好的IDE来避免这个愚蠢的错误
要为响应提供额外的数据,可以构造返回的数组数据
return new JsonResponse([
'someData' => $resultado,
'html' => $this->render('others/adminlte.html.twig')
);
发布于 2018-07-25 18:44:56
像@goto的答案,但它不会起作用,因为你需要使用renderView
而不是render
return new JsonResponse([
'things' => $thingsArray,
'anotherVariable' => $simpleVariable,
'html' => $this->renderView('others/adminlte.html.twig', []/* template parameters goes here */),
]);
https://stackoverflow.com/questions/48897415
复制相似问题