Lange Geschichte kurz: Mit FOSRestBundle versuche ich einige Entitäten per POST-Aufruf zu erstellen, oder modifiziere existierend via PUT.FosRestBundle post/put [Erzeuge/aktualisiere Entität] liest nicht korrekt an
hier der Code:
/**
* Put action
* @var Request $request
* @var integer $id Id of the entity
* @return View|array
*/
public function putCountriesAction(Request $request, $id)
{
$entity = $this->getEntity($id);
$form = $this->createForm(new CountriesType(), $entity, array('method' => 'PUT'));
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->view(null, Codes::HTTP_NO_CONTENT);
}
return array(
'form' => $form,
);
} //[PUT] /countries/{id}
Wenn ich rufe/Länder/{id} mit PUT eine json wie { "description": "Japan"} vorbei, es ist mein Land ändern mit id = 1, Putting eine leere Beschreibung.
Wenn stattdessen ich versuche, eine neue Einheit mit dieser Methode zu erstellen:
/**
* Create new Countries (in batch)
* @param Request $request json request
* @return array redirect to get_coutry, will show the newly created entities
*/
public function postCountriesAction(Request $request)
{
$entity = new Countries();
$form = $this->createForm(new CountriesType(), $entity);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirectView(
$this->generateUrl(
'get_country',
array('id' => $entity->getId())
),
Codes::HTTP_CREATED
);
}
return array(
'form' => $form,
);
} //[PUT {"description":"a_description"}] /countries
es gibt mir eine Fehlermeldung,:
exception occurred while executing 'INSERT INTO countries (description) VALUES (?)' with params [null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'description' cannot be null
so scheint, dass ich nicht in der Lage bin zu passieren richtig die Anfrage an das Formular zu binden.
Beachten Sie, dass, wenn ich die Anfrage json_decode als here es mit einem
{
"code":400,
"message":"Validation Failed",
"errors":{
"errors":[
"This value is not valid."
],
"children":{
"description":[
]
}
}
}
Jede Beratung
vorgeschlagen antworten?Danke, Rolls
leider stellen, dies nicht den Trick tut ... Es scheint, i‘ Ich bin nicht in der Lage, die Anfrage an das Formular zu binden ... was ich [aus debug] habe: 'Anfrage: PUT' ' Anfrage: Array ([Beschreibung] => Japan) ' ' Einheit aus db: Länder Objekt ([id: protected] => 1; [Beschreibung: protected] => Italien) ' ' aus form-> getData() form: Länder Objekt <- ([id: protected] => 1; [description: protected] =>) was es speichert: entity: Countries Object ([id: protected] => 1; [Beschreibung: protected] =>) ' – rollsappletree