May I ask why the put contains only an empty field? While the post is working normally?
$app->post('/books', function (Request $request, Response $response, $args){
$book = Books::fromResultSet($request->getParsedBody());
if($book->valid())
return $response->withStatus(400);
$book->insert();
return $response->withStatus(201);
})->add($securityMiddleware);
$app->put('/books/{id}', function (Request $request, Response $response, $args){
$book = Books::fromResultSet($request->getParsedBody());
print_r($book);
/*if($book->valid())
return $response->withStatus(400);
$book->update();
return $response->withStatus(201);*/
})->add($securityMiddleware);
Errors after listing print_r ($ request-> getParsedBody ())
C:\MAMP\htdocs\vendor\slim\slim\Slim\Handlers\Strategies\RequestResponse.php(43): {closure}(Object(GuzzleHttp\Psr7\ServerRequest), Object(GuzzleHttp\Psr7\Response), Array)
#1 C:\MAMP\htdocs\vendor\slim\slim\Slim\Routing\Route.php(384): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(GuzzleHttp\Psr7\ServerRequest), Object(GuzzleHttp\Psr7\Response), Array)
#2 C:\MAMP\htdocs\public\index.php(27): Slim\Routing\Route->handle(Object(GuzzleHttp\Psr7\ServerRequest))
#3 C:\MAMP\htdocs\vendor\slim\slim\Slim\MiddlewareDispatcher.php(313): {closure}(Object(GuzzleHttp\Psr7\ServerRequest), Object(Slim\Routing\Route))
#4 C:\MAMP\htdocs\vendor\slim\slim\Slim\MiddlewareDispatcher.php(81): class@anonymous->handle(Object(GuzzleHttp\Psr7\ServerRequest))
#5 C:\MAMP\htdocs\vendor\slim\slim\Slim\MiddlewareDispatcher.php(81): Slim\MiddlewareDispatcher->handle(Object(GuzzleHttp\Psr7\ServerRequest))
#6 C:\MAMP\htdocs\vendor\slim\slim\Slim\Routing\Route.php(341): Slim\MiddlewareDispatcher->handle(Object(GuzzleHttp\Psr7\ServerRequest))
#7 C:\MAMP\htdocs\vendor\slim\slim\Slim\Routing\RouteRunner.php(84): Slim\Routing\Route->run(Object(GuzzleHttp\Psr7\ServerRequest))
#8 C:\MAMP\htdocs\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php(59): Slim\Routing\RouteRunner->handle(Object(GuzzleHttp\Psr7\ServerRequest))
#9 C:\MAMP\htdocs\vendor\slim\slim\Slim\MiddlewareDispatcher.php(147): Slim\Middleware\RoutingMiddleware->process(Object(GuzzleHttp\Psr7\ServerRequest), Object(Slim\Routing\RouteRunner))
#10 C:\MAMP\htdocs\vendor\slim\slim\Slim\Middleware\ErrorMiddleware.php(107): class@anonymous->handle(Object(GuzzleHttp\Psr7\ServerRequest))
#11 C:\MAMP\htdocs\vendor\slim\slim\Slim\MiddlewareDispatcher.php(147): Slim\Middleware\ErrorMiddleware->process(Object(GuzzleHttp\Psr7\ServerRequest), Object(class@anonymous))
#12 C:\MAMP\htdocs\vendor\slim\slim\Slim\MiddlewareDispatcher.php(81): class@anonymous->handle(Object(GuzzleHttp\Psr7\ServerRequest))
#13 C:\MAMP\htdocs\vendor\slim\slim\Slim\App.php(215): Slim\MiddlewareDispatcher->handle(Object(GuzzleHttp\Psr7\ServerRequest))
#14 C:\MAMP\htdocs\vendor\slim\slim\Slim\App.php(199): Slim\App->handle(Object(GuzzleHttp\Psr7\ServerRequest))
#15 C:\MAMP\htdocs\public\index.php(85): Slim\App->run()
CodePudding user response:
If this still errors, please try to update Slim 4 to latest version and try again.