Hi im trying to dend data to my method in the controller using an ajax script :
$("#form_enr").submit(function(ev) {
ev.preventDefault();
var ev = $("#mySelect").val();
var text =$("#form_Text").val();
console.log(text);
console.log(ev);
$.ajax({
type: "POST",
url: "{{ path('invitation_enregistrerInv')}}",
data : 'ev=' + ev + '&text=' + text,
success: function(data){
$('.portlet-body').html(data);
}
});
});
and to get it I use this syntax :
public function enregistrerInvAction()
{
$inv = new Invitation();
$em = $this->getDoctrine()->getManager();
$request = $this->get('request');
$ev = $request->request->get('ev');
$text = $request->request->get('text');
$inv->setCreatedAt(new \Datetime());
$inv->setUpdatedAt(new \Datetime());
$inv->setText($text);
$em->persist($inv);
$evenement=$em->getRepository('EvEvenementBundle:Evenement')->findById($ev);
$evenement=new Evenement();
$evenement->setInvitation($inv);
$em->persist($evenement);
$em->flush();
$this->addFlash(
'success',
'Les informations ont été enregistrées!'
);
return $this->redirect($this->generateUrl('invitation_index2'));
}
but i seems not working, because I have this error :
An exception occurred while executing 'INSERT INTO invitation (created_at, updated_at, text) VALUES (?, ?, ?)' with params ["2016-08-01 17:12:55", "2016-08-01 17:12:55", null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Le champ 'text' ne peut être vide (null) !!! because text is null , and I don't get it
Requestinjection in you controllers,'request'in the container has been deprecated in favor of the'request_stack'