私はsymfony3でmysqlデータベースにデータを投稿する関数を持っています。私は、文字列のポスト要求作品で変数($ピース、$タイプ、$たstartDate、endDateに$)を交換するときSymfony 3で投稿をリクエストしていますか?
/**
* @Route("/LegoPieces")
* @METHOD("POST")
* @View()
*
* @Annotations\QueryParam(
* name="piece", nullable=false, description="piece"
*)
* @Annotations\QueryParam(
* name="type", nullable=false, description="type"
*)
* @Annotations\QueryParam(
* name="startDate", nullable=false, description="Start Date YYYY-MM-DD HH:MM:SS (Should be in the future)"
*)
* @Annotations\QueryParam(
* name="endDate", nullable=false, description="End Date YYYY-MM-DD HH:MM:SS (Should be no more than 3 weeks in the future)"
*)
*/
public function postAction(ParamFetcherInterface $paramFetcher)
{
$piece = $paramFetcher->get('piece');
$type = $paramFetcher->get('type');
$start = $paramFetcher->get('startDate');
$end = $paramFetcher->get('endDate');
$startDate = DateTime::createFromFormat('Y-m-d H:i:s', $start);
$endDate = DateTime::createFromFormat(' Y-m-d H:i:s', $end);
$em = $this->getDoctrine()->getManager('default');
$data = new LegoPieces();
$data->setPiece($piece);
$data->setType($type);
$data->setStartDate($startDate);
$data->setEndDate($endDate);
$em->persist($data);
$em->flush();
return new JsonResponse("LegoPieces Added Successfully", 200);
}
:関数は次のようになります。しかし、私が郵便配達員やjavascriptのようなもので投稿リクエストをしようとすると、次のようになります:
fetch("http://localhost:8000/LegoPieces", {
method: "POST",
body: {
startDate: this.startDate,
endDate: this.endDate,
piece: this.piece,
type: this.type
}
}).then(response => response.json())
);
});
私は500エラーが発生します!私は理解していません - 助けてくれてありがとう!
あなたはsymfonyのプロファイラの結果を確認しましたか? – LugiHaue