0

I am trying to use Symfony 2 with FOSRestBundle, I've got my GET and POST functions working fine and i've got it returning an array fine with PUT however i cannot get my query string or input.

I've tried the obvious $_POST, $_GET, $_PUT and even tried file_get_contents("php://input"); none of these return a query string.

I am lead to believe that PUT is used to update an existing entry which i am doing.

Any assistance would be greatly appreciated.

Glow
  • 41
  • 2
  • 10
  • There is no $_PUT. The confusion may arise from the fact that $_GET and $_POST are named after the HTTP verbs. Whetever HTTP verb you are using to operate on a resource, you will be able to access both to posted data and query string paramaters. In a Symfony controller, you access those data with $this->getRequest()->request ($_POST) and $this->getRequest()->query Relevant documentation: http://symfony.com/doc/current/components/http_foundation/introduction.html – Giovanni Oct 23 '14 at 12:50
  • My apologies.I've tried installing http_foundation but it acts like the query string is totally empty. Just to note that i am using the RESTConsole chrome extension for testing and im passing various payload requests (query string) which go fine if i POST but when i PUT they dont arrive at all. – Glow Oct 23 '14 at 15:28

1 Answers1

0

That's documented here: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/3-listener-support.md#param-fetcher-listener

Let me give you an example:

/**
 * @View(statusCode=200)
 * @Put("/resource/{resource_id}")
 * @QueryParam(name="page", requirements="\d+", default="1", description="Page of the overview.")
 */
public function putAction(ParamFetcher $paramFetcher)
{
    $page = $paramFetcher->get('page');
    ...
}

That way you'll be able to fetch query params.

piotr.jura
  • 810
  • 9
  • 17