这是我的控制器。在大多数情况下,它工作得很好,并为我返回了一个很好的JSON对象。但在一些实体上,它只是挂在下面的行上。我的实体中数据的完成情况各不相同,在缺少特定字段和序列化无法工作之间似乎没有联系
此外,我的正常视图工作得很好,只是串行器似乎工作不正常。
其他人对Symfony的内置序列化程序有问题吗?
编辑:进行了更深入的查看,看起来我正在为此使用JMSSerializerBundle。
$em = $this->getDoctrine()->getManager('inertia');
$entity = $em->getRepository('InertiaBundle:Accounts')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Accounts entity.');
}
if($format == 'json') {
// return json array
$serializer = $this->get('serializer');
$data = $serializer->serialize($entity, 'json'); //hangs at this line.
$response = new Response($data);
$response->headers->set('Content-Type', 'application/json');
return $response;
} else {
$deleteForm = $this->createDeleteForm($id);
return $this->render('InertiaBundle:Accounts:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
));
}
我有一个类似的问题,请求挂在下面的行上:
$serializer = $this->get('serializer');
用以下内容替换它似乎有效
$serializer = $this->container->get('serializer');
我还不太了解Symfony2,不知道为什么会出现这种情况,但也许有比我更了解的人可以解释。