Reputation:
I have function
/**
* My function
*
* @FOS\View()
* @FOS\Get("/myfunction/?param1={p1}¶m2={p2}¶mn={pn}")
*
* @param integer $param1
* @param integer $param2
* @param integer $paramn
* @return mixed
*/
public function getMyFunction($param1, $param2, $paramn)
{
return new Response($param1. ' ' . $param1. ' ' . $paramn);
}
But when I call http://host/myfunction/?param1=1¶m1=2¶mn=3 dosen't work.
What is wrong in definition of function?
UPDATE: New function
/**
* My function
*
* @FOS\View()
* @FOS\Get("/myfunction/")
*
* Request $request
* @return mixed
*/
public function getMyFunction(Request $request)
{
$requestParams = $request->request->all();
return new Response($requestParams['param1']);
}
And, now I call http://host/myfunctin/?param1=1, but still, dosen't work.
Error: "Notice: Undefined index: param1"
Request for get parameters isn't good?
Thanks!
Upvotes: 0
Views: 42
Reputation: 1431
You have to remove the query string parameters from the route.
To get them you have to inject a Request object in the function signature and the use $request->get('parametername') to retrieve then.
Upvotes: 1