私はスリム3のミドルウェアとしてjustinrainbowからJSONスキーマバリデータを実装するためにスリム3ミドルウェアの検証
をしようとしている私はでGET/POSTリクエストからクライアントの入力を取得する方法を見つけ出すことはできませんミドルウェア。 は次のように試してみました:私はそれを必要とする方法の2つの可能な方法があります
$mw = function ($request, $response, $next) { $data = $request->getParsedBody(); print_r($data); // prints nothing $id = $request->getAttribute('loan_id'); print_r($id); // prints nothing // here I need to validate the user input from GET/POST requests with json-schema library and send the result to controller $response = $next($request, $response); return $response; }; $app->get('/loan/{loan_id}', function (Request $request, Response $response) use ($app, $model) { $loanId = $request->getAttribute('loan_id'); // here it works $data = $model->getLoan($loanId); $newResponse = $response->withJson($data, 201); return $newResponse; })->add($mw);
。私は間違っているの?
ミドルウェアでそれを検証し、コントローラにいくつかの配列/ JSON応答を送信、私は私は
$data = $request->getParsedBody();
で理解されるようにミドルウェアでそれを検証してしまいますが、最終チェックは、このようなコントローラにされます:それは何かする私のために
$app->get('/loan/{loan_id}', function (Request $request, Response $response) use ($app, $model) { if($validator->isValid()){ // } $loanId = $request->getAttribute('loan_id'); // here it works $data = $model->getLoan($loanId); $newResponse = $response->withJson($data, 201); return $newResponse; })->add($mw);
ベストオプションgのようなhere しかし、私はコンテナに戻って、どのように取得する必要があります/投稿の入力をコンテナに取得/投稿入力を理解していません
ミドルウェアでは 'print_r()'だけではできません。代わりに '$ response-> write(print_r($ data)、true))のようなものを試してみてください。' ' –