ace ofglad
ace ofglad

Reputation: 31

Slim framework, what to use instead of getParsedBody for put method?

I'm trying to build a rest API with the slim framework, however I have some trouble with the put request which doesn't allow GetParsedBody, I looked a lot on internet but didn't find usable method, the only one who worked is :parse_str($request->getBody()->getContents(), $icone); where icone is the variable to return.

Here is my code if you want to see it but i don't matter for this question, thank you for your time !

$app->put('/{id}', function($request, $response, $args) use ($app){

    $boucle = array();
    $route = $request->getAttribute('route');
    $courseId = $route->getArgument('id');

    parse_str($request->getBody()->getContents(), $icone);

    return $response->withJson($icone);
});

Upvotes: 0

Views: 1214

Answers (2)

Ramy hakam
Ramy hakam

Reputation: 542

Try this

    $route=$req->getParsedBodyParam('route');
    $id=$req->getParsedBodyParam('id');

Upvotes: 2

odan
odan

Reputation: 4952

Try this:

parse_str($request->getBody()->__toString(), $icone);

Upvotes: 0

Related Questions