In a page, i have some element which users can click to edit. I want to add a function to edit the date with a simple drag ot the event in a calendar grid. The user could quickly edit the date by dragging the event down, or click on the event to edit more things.
For now, I want to persist my entity with an ajax call when the user click on an event. I can retrieve my data (event' id and the start_date)I tried to put them in a simple .txt file and it work.
My ajax :
var start_date = event.start_date;
var id = id;
var edit = Routing.generate('admin_event_edit', {id : id});
$.ajax({
url: Routing.generate('admin_event_edit', {id : id}),
type: "POST",
data: { id : id, start_date : start_date},
success: function(data) {
alert('ok');
},
error: function(){
alert('error');
}
});
i have a form at the route admin_event_edit
And in my controller :
public function editAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('AppBundle:Event')->find($id);
$starDate = $request->request->get('start_date');
$editForm = $this->createForm(new EventType(), $entity);
$editForm->handleRequest($request);
if ($editForm->isValid())
{
if($request->isXmlHttpRequest())
{
$entity->setStartDate($starDate);
$entity->setNotice('azeazedfdf');
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
}
}
return $this->redirect($this->generateUrl('admin_index'));
}
I have the ajax alert ok and i can see the ajax call has been sent in the symfony profiler, but my entity isn't updated.
What's wrong with my code ?
Thanks
$editForm->isValid()?