0

I have function

/**
 * My function
 *
 * @FOS\View()
 * @FOS\Get("/myfunction/?param1={p1}&param2={p2}&paramn={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&param1=2&paramn=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!

2
  • 1
    With @FOS\Get you can specify only the path. If you need to get parameters on the query string, you can do that with the request object. Commented Apr 13, 2017 at 6:40
  • You want use the query parameter bag instead of request Commented Apr 13, 2017 at 6:55

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I changed with request, but don't work. I updated the initial post with current version of code.
Try $request->get('param1')
Thanks, Carols! Work! Thanks, Federkun for explication about @FOS\Get.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.