No @QueryParam/@RequestParam configuration
My action in controller:
/*
* @REST\QueryParam(name="page", requirements="\d+", default="1", description="page number")
* @REST\QueryParam(name="pageSize", requirements="\d+", default="25", description="users per page")
* @REST\View()
*/
public function allAction(ParamFetcher $paramFetcher)
{
$pageSize = $paramFetcher->get('pageSize');
$page = $paramFetcher->get('page');
$users = $this->get('backend.user.handler')->all($pageSize, $pageSize * $page - 1);
return $users;
}
The config of FOSRestBundle:
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: false
view:
view_response_listener: 'force'
And the routing for this route:
backend_get_all_users:
pattern: /users
defaults: { _controller: MyBackendBundle:User:all, _format: json }
requirements:
_method: GET
When I try to visit this route I get
No @QueryParam/@RequestParam configuration for parameter 'pageSize'
What am I missing?
hmm I do not see anything wrong from a quick look either. Did you clear your cache?
Yes the cache is cleared but still I get that error in both the prod and dev environments.
does it work with page ?
No , if i remove $pageSize = $paramFetcher->get('pageSize'), I get
No @QueryParam/@RequestParam configuration for parameter 'page'
I assume you have use FOS\RestBundle\Controller\Annotations as REST; in your code?
if so .. I fear you will have to debug this inside the ParamFetcher (and the ParamFetcherReader) or try to reproduce the issue inside https://github.com/gimler/symfony-rest-edition and send me a PR with the test case.
Well, HERE I get emty array, after reading the params.
ok then the issue is in the ParamReader
Found the problem, nooby problem.
There was /* instead of /** in method comment section.
I ran into a similar problem and it was also because and invalid comment in the comments section
In my case it was a whitespace in the fetcher parameter string