Hello,
Using Slim\Psr7\Request or Psr\Http\Message\ServerRequestInterface, in Slim 4, in my controller or in my middleware, I’d like to call request->getParsedBodyParam(‘firstname’) as I used to do in Slim 3. But I get the error “Call to undefined method Slim\Psr7\Request::getParsedBodyParam()”
Where is that function, in Slim 4 ?
thx
Hi!
In Slim 4, given the Request I’m using the getParsedBody() function to get the data.
Example:
$data = $request->getParsedBody();
(I also used to do getParsedBodyParam() in Slim 3).
Ex:
$foo = $request->getParsedBodyParam('foo', null);
Maybe in S4 was removed the method getParsedBodyParam because is not part of the PSR-7…
Thx,
I think it has been removed from Slim 4
I added a function in my code:
public static function getParsedBodyParam(Request $request, string $key, $default = null) {
$postParams = $request->getParsedBody();
$result = $default;
if (is_array($postParams) && isset($postParams[$key])) {
$result = $postParams[$key];
} elseif (is_object($postParams) && property_exists($postParams, $key)) {
$result = $postParams->$key;
}
return $result;
}
1 Like