Slim v3を使用しています。作曲家経由でインストールされます。私は私がのRuntimeExceptionエラーCould not write to stream
を取得する郵便配達を経由して{"name":"jack", "age":"10", "gender":"male"}
のようなサンプルJSONを投稿するSlim v3を使用してJSON POSTデータを取得する
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
$app = new \Slim\App(['settings' => ['displayErrorDetails' => true]]);
//-------------- Register ------------------
$app->post('/', function (Request $request, Response $response ,$args) use($app) {
$json =$request->getParams();
$data = json_decode($json, true);
$response->getBody()->write($data);
return $response;
});
$app->run();
: はここに私のregister.phpファイルです。 私は既に$app->request()->post();
と$request->getParams();
と$request->getParsedBody();
を使用していますが、未定義の方法などの他のエラーに直面しています。 私を助けてください。
感謝を使用することができます。問題は依然として存在する。私は$ argsのためだと思う。 本当にそれが必要ですか?または使用する($ app)@iturki –
@ mehrdad-pedramfar私はそうは思わない。スリム3または2を使用していますか? – iTurki
バージョン3.私はそれを描き出す!問題は$ argsでした。 –