gpt4 book ai didi

php - FOSRestBundle : ParamFetcher error

转载 作者:行者123 更新时间:2023-12-01 22:09:52 24 4
gpt4 key购买 nike

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

```

   /**
* @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 调用我的节点时,出现了这个错误:

Controller and method needs to be set via setController

错误来自ParamFetcher,而行

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

您是否知道此问题的起源:/?

最佳答案

只需在 Symfony 的 config.yml 中启用参数 getter 监听器:

fos_rest:
param_fetcher_listener: true

关于php - FOSRestBundle : ParamFetcher error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48723114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com