Answer the question
In order to leave comments, you need to log in
Symfony - Serializer, Normalizer, Deserializer how to convert Array to Entity Object?
Hello everyone,
does anyone know how to convert an Array to an Entity Object?
the following json is sent:
{
"data": {
"object_nr": 565656,
"title": "My Title",
"categorie_id": 3
}
}
/**
* @ParamConverter("immo", converter="fos_rest.request_body")
*/
public function postImmoAction(Immo $immo, Request $request)
{
$data = $request->request->all();
$immo->setCreatedAt(new DateTime());
$immo->setUpdatedAt(new DateTime());
$em = $this->getDoctrine()->getManager();
$categorie = $em->getRepository(Immo\Categorie::class)->find($request->request->get($data['categorie_id']);
это ManyToOne Realtion:
$immo->setCategorie($categorie);
$immo->setUser($this->getUser());
$em->persist($immo);
$em->flush();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question