FOSRestBundle无法找到模板,无法返回json

时间:2015-03-26 10:25:28

标签: json symfony fosrestbundle

我不想使用FOSRestBundle从api返回json响应,但是FOSRestBundle希望返回twig而不是json。

我的控制器方法看起来像这样

/**
 * @Rest\Post("/producers-from-points",name="get-producers-from-points",options={"expose"=true})
 * @Rest\View(serializerGroups={"list"}, statusCode=200)
 *
 * @return \FOS\RestBundle\View\View
 * @throws \Exception
 */
public function getProducersFromPointsAction()
{
    $json = parent::getJsonFromRequest();
    if($json===false){
        throw new \Exception("");
    }

    /** @var EntityManager $em */
    $em = $this->getDoctrine()->getManager();

    $poss = $em->getRepository('AppBundle:PointOfSale')->getPointOfSalesByAroundPoints($json->points);

    return ['pointsOfSales'=>$poss];
}

config.yml

fos_rest:
  routing_loader:
    default_format: json
    include_format: false
  param_fetcher_listener: true
  body_listener:          true
  format_listener:        false
  view:
    view_response_listener: 'force'
  exception:
    messages:
        'Exception': true

1 个答案:

答案 0 :(得分:1)

尝试将view_reponse_listener设置为“false”而不是“force”。

看看这里更好地了解view_reponse_listener是什么: http://symfony.com/doc/current/bundles/FOSRestBundle/3-listener-support.html