Trendfischer Trendfischer - 2 years ago 182
PHP Question

PSR7 combine GET and POST 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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download