FOSRestBundle:ParamFetcher 错误 [英] FOSRestBundle : ParamFetcher error

查看:30
本文介绍了FOSRestBundle:ParamFetcher 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用 FOSRestBundle我已将此路由配置为可以访问不同的 kinf 数据:

I'm Using FOSRestBundle for my project I've configured this route to have access to different kinf of data :

```

   /**
     * @Rest\Get("")
     *
     * @Rest\QueryParam(
     *     name="categoriesId",
     *     requirements="[0-9a-zA-Z\- \/_:.,\s]",
     *     default="",
     *     description="The categories ids."
     * )
     * @Rest\QueryParam(
     *     name="orderBy",
     *     requirements="[a-zA-Z0-9]",
     *     default="score",
     *     description="The keyword to search for."
     * )
     * @Rest\QueryParam(
     *     name="order",
     *     requirements="asc|desc",
     *     default="desc",
     *     description="Sort order (asc or desc)"
     * )
     * @Rest\QueryParam(
     *     name="limit",
     *     requirements="\d+",
     *     default="-1",
     *     description="Max number of celebrities returned."
     * )
     * @Rest\QueryParam(
     *     name="offset",
     *     requirements="\d+",
     *     default="0",
     *     description="The offset"
     * )
     *
     * @Rest\View(serializerEnableMaxDepthChecks=true)
     * @param ParamFetcherInterface $fetcher
     * @param EntityManagerInterface $em
     * @return array
     */
    public function getAction(ParamFetcherInterface $fetcher, EntityManagerInterface $em) {
        // Get categories
        $categories_id = explode(',', $fetcher->get('categoriesId'));

        $options = [
            'addProfilePicture' => true,
            'addCategories' => true,
        ];

        // Configure limit and order
        if($fetcher->get('limit') !== -1)
            $options['limit'] = $fetcher->get('limit');

        $options['offset'] = $fetcher->get('offset');

        // Configure order
        switch ($fetcher->get('orderBy')) {
            case 'score':
                $options['orderBy'] = 'score';
        }

        $rows = $em->getRepository(Celebrity::class)->findByCategories($categories_id, $options);

        return $rows;
    }

```

但是当我使用 Postman 调用我的节点时,出现此错误:

But when I call my node with Postman, I've this error :

控制器和方法需要通过setController设置

Controller and method needs to be set via setController

错误来自ParamFetcher,还有一行

And the error come from the ParamFetcher, and the line

$categories_id = explode(',', $fetcher->get('categoriesId'));

你知道这个问题的起源吗:/?

Do you have any idea about the origin of this issue :/ ?

推荐答案

只需在 Symfony 的 config.yml 中启用 param fetcher listener:

Just enable param fetcher listener in your Symfony's config.yml:

fos_rest:
    param_fetcher_listener: true

这篇关于FOSRestBundle:ParamFetcher 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆