FOSRestBundle无法获取param fetcher

Iva*_*eev 2 php rest symfony fosrestbundle

我正在尝试让我的控制器与param fetcher一起工作.我做了文档中指定的所有说明.所以我有:config fos_rest.yml:

fos_rest:
  param_fetcher_listener: 'force'
  view:
      formats:
          json: true
          xml: false
          rss: false
      mime_types:
          json: ['application/json', 'application/x-json', 'application/vnd.example-com.foo+json']
          png: 'image/png'
      failed_validation: HTTP_BAD_REQUEST
      default_engine: twig
      view_response_listener: 'force'
  format_listener:
      default_priorities:
          - json
  routing_loader:
      default_format: json
Run Code Online (Sandbox Code Playgroud)

sensio_framework_extra:view:{annotations:false} router:{annotations:true}

而我的控制器

<?php

namespace Push\PointsBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use FOS\RestBundle\View\View;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use FOS\RestBundle\Request\ParamFetcher;

class RestController extends Controller
{
    /**
     * @QueryParam(name="latitude", requirements="[0-9.]+", default="0", description="")
     * @ApiDoc()
     */
    public function checkPointsAction(ParamFetcher $params)
    {
        $view = new View();
        return $this->get('fos_rest.view_handler')->handle($view);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我调用方法时,我得到:

控制器"Push\PointsBundle\Controller\RestController :: checkPointsAction()"要求您为"$ params"参数提供一个值(因为没有默认值或者因为在此之后存在非可选参数).

我做错了什么或错过了什么?谢谢.

Jak*_*las 10

我经常遇到FOSRestBundle和过时的缓存问题.如果我在注释中进行更改,它有时不会刷新.首先,尝试删除app/cache目录的内容(rm -rf app/cache/*).

我没有检查参数是否通过类型或名称映射到方法参数.如果它比你的参数更晚应该被调用$paramFetcher(不是$params):

public function checkPointsAction(ParamFetcher $paramFetcher) { }
Run Code Online (Sandbox Code Playgroud)

编辑:你启用了param fetcher监听器吗?

fos_rest:
    param_fetcher_listener: true
Run Code Online (Sandbox Code Playgroud)