Trendfischer Trendfischer - 2 months ago 14x
PHP Question

PSR7 Request: Get request data like $_REQUEST in Slim3

I am refactoring my application using PSR-7 Requests using Slim3 as Router. On some of my entry points I have incoming GET and POST HTTP-Requests from external applications. Both GET and POST use the same parameter names. In the old code, a simple

solved the issue, but I do not want to use the superglobals any longer.

For getting the parameters of the GET-Request, I use the following code:

$parameters = $request->getQueryParams();

For the POST-Request, I use:

$parameters = $request->getParsedBody();

Is there a PSR-7 function for solving the issue, or do I have to use
each time?


Slim's request object has getParam() and getParams() which does what you want. These are not part of PSR-7 though.