나는 Symfony3에서 데이터를 mysql 데이터베이스에 게시하는 기능을 가지고있다. 이 기능은 다음과 같습니다 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);
}
내가 POST 요청 작동 문자열 변수 ($ 조각, $ 유형, $ startDate를, $ endDate가)를 대체
. 그러나 Postman이나 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 오류가 발생합니다! 너의 도움에 감사한다.
는 심포니 프로파일 결과를 확인 했습니까? – LugiHaue