如何从JMS Serializer获取始终数组?

时间:2014-05-23 08:18:39

标签: symfony doctrine fosrestbundle jmsserializerbundle

/**
 * This function is used to get all Stopes.
 *
 * @ApiDoc(
 *  resource=true,
 *  section="Stop",
 *  description="This function is used to get all Stopes",
 *  statusCodes={
 *         200="Returned when successful",
 *         404="Returned when the Stop is not found"
 *     }
 * )
 *
 * @return mixed
 * @Rest\View(serializerGroups={"main"})
 */
public function cgetAction()
{
    $em = $this->getDoctrine()->getManager();
    $stopes = $em->getRepository(self::ENTITY)->findAll();

    return $stopes;
}

我使用JMS Serializer进行休息。

这是来自Rest控制器的代码。它返回json或数组(服务器,localhost)。如何获得ALWAYS数组响应?

1 个答案:

答案 0 :(得分:1)

我找到了回答

 /**
 * This function is used to get all Stopes.
 *
 * @ApiDoc(
 *  resource=true,
 *  section="Stop",
 *  description="This function is used to get all Stopes",
 *  statusCodes={
 *         200="Returned when successful",
 *         404="Returned when the Stop is not found"
 *     }
 * )
 *
 * @return mixed
 * @Rest\View(serializerGroups={"main"})
 */
public function cgetAction()
{
    $em = $this->getDoctrine()->getManager();
    $stopes = $em->getRepository(self::ENTITY)->findAll();


    return array_values($stopes);
}