【发布时间】:2014-08-16 08:12:35
【问题描述】:
我有一个小问题,我正在尝试发送一个 json 响应,但我得到的只是一个空对象。
这是我的代码:
//Get the data from DB
$template = $this->getDoctrine()
->getRepository('EVRYgroBundle:Template')
->findOneBy(
array('active' => 1)
);
if (!$template) {
throw $this->createNotFoundException(
'No product found for id '
);
}
//Send the response
$response = new Response();
$response->setContent(json_encode($template));
return $response;
当我查看它时,它显示的只是 {} 我也尝试过使用 jsonResponse 和这段代码:
$response = new JsonResponse();
$response->setData($template);
而且我不知道我做错了什么!
【问题讨论】: