Answer the question
In order to leave comments, you need to log in
Why is there no DB entry via AngularJS API and Symfony 4?
In general, there is a post request from Angular to Symfony with parameters. But there is an error "Call to a member function setName() on null". But if you run the request through the PhpStorm tool, everything works.
Method:
/**
* @Route("/rest_api/update", methods={"POST"})
*/
public function restApiUpdate(Request $request)
{
$id = $request->request->get('id');
$user = $request->request->get('user');
$user = urldecode($user);
$em = $this->getDoctrine()->getManager();
$modelUser = $em->getRepository(Users::class)->find((int)$id);
$modelUser->setName($user);
$em->flush();
return new JsonResponse($id);
}
$http({method: 'POST', url: 'http://public/rest_api/update', params: {'id': id, 'user': user}}).
then(function success (response) {
$scope.response=response.data;
console.log(user);
});
Answer the question
In order to leave comments, you need to log in
bears was right, we need to fix the request:
$http({method: "POST", url: "http://public/rest_api/update", headers: {'Content-Type': undefined}, data: {id: id, user: user}}).
then(function success (response) {
$scope.response=response.data;
console.log(user);
});
$postdata = file_get_contents("php://input");
$data = json_decode($postdata);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question