En el archivo edit.html.twig de la Entidad AbcMembers esta el bloque "javascripts_foraneas" donde se raeliza la llamada Ajax y usando el firebug efectivamente verifico que se envian los datos.
Código HTML:
Ahora les muestro el codigo del controlador de la Entidad ABCMEmbersPersonalIdController, donde recibo los parametros via Ajax y Setteo los valores a la entidad que necesito persistir, pero no me guarda nada. Alguna sugerencia de que estoy haciendo mal ??Ver original
{% extends "ABCPreEnrollmentBundle:EnrollLayout:plantillaTabs.html.twig" %} {% block body -%} {{form_start(edit_form)}} {{form_errors(edit_form)}} <div class="row-fluid"> </div> <div class="row-fluid"> <div class="span12"> <div class="span4 offset2"> {{form_row(edit_form.lastname, {'attr':{'class': 'span10'}})}} {{form_row(edit_form.firstname, {'attr':{'class': 'span6'}})}} {{form_row(edit_form.middlename, {'attr':{'class': 'span6'}})}} {{form_errors(edit_form.birthdate)}} {{form_label(edit_form.birthdate)}} {{form_widget(edit_form.birthdate.day, {'attr':{'class': 'span3'}})}} {{form_widget(edit_form.birthdate.month, {'attr':{'class': 'span3'}})}} {{form_widget(edit_form.birthdate.year, {'attr':{'class': 'span3'}})}} {{form_row(edit_form.gender)}} </div> <div class="span6"> {{form_row(edit_form.placeOfBirthdate, {'attr':{'class': 'span8'}})}} {{form_row(edit_form.sitewideLogin, {'attr':{'class': 'span4'}})}} {{form_row(edit_form.document, {'attr':{'class':'span4'}})}} <input type="text" class="span4" id="document_id"> <input type="text" class="span4" id="nit"> <input type="text" class="span4" id="mobile_phone"> <input type="hidden" id="member_id" name="nombre" value={{entity.id}}> <br> </div> </div> </div> <div class="modal-footer"> {{form_widget(edit_form.submit, {'attr':{'class':'btn btn-primary'}})}} </div> {{form_end(edit_form)}} {% block javascripts_foraneas %} <script> $(document).ready(function(){ }); $('#document_id').blur(function(){ $.post( '{{path('preenrollment_personalid_documents')}}', { document_type:$("#abc_preenrollmentbundle_abcmembers_document").val(), document_id :$("#document_id").val(), member_id :$("#member_id").val() } ).done(function(data){ $("#mobile_phone").html(data); }); }); </script> {%endblock%} {% endblock %}
Código PHP:
/**
* Lists all AbcMembersPersonalId entities.
*
* @Route("/documents", name="preenrollment_personalid_documents")
* @Method("POST")
* @Template()
*/
public function documentsAction(Request $request)
{
$isAjax = $this->get('Request')->isXMLhttpRequest();
if($isAjax){
$document_type =$this->get('request')->request->get('document_type');
$document_id =$this->get('request')->request->get('document_id');
$member_id =$this->get('request')->request->get('member_id');
$em = $this->getDoctrine()->getManager();
$entity = new AbcMembersPersonalId();
$entity->setIdType($document_type);
$entity->setMember($member_id);
$entity->setDocument($document_id);
$entity->setCreatedDate(new DateTime());
$validator = $this->get('validator');
$errors = $validator->validate($entity);
$resultado="";
var_dump($errors);
if(count($errors)==0){
$em->persist($entity);
$em->flush();
$resultado="exito";
}else{
$resultado="fracaso";
}
$response = new JsonResponse();
return $response->setData($resultado);
}else{
return new Response('0');
}
}
Código PHP:
De ante mano les agradezco su valiosa ayuda. Ver original
<?php namespace ABC\PreEnrollmentBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * AbcMembersPersonalId * * @ORM\Table(name="abc_members_personal_id") * @ORM\Entity(repositoryClass="ABC\PreEnrollmentBundle\Repository\AbcMembersPersonalIdRepository") */ class AbcMembersPersonalId { /** * @var integer * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var string * * @ORM\Column(name="document", type="string", length=45, nullable=false) */ private $document; /** * @var \DateTime * * @ORM\Column(name="created_date", type="datetime", nullable=false) */ private $createdDate; /** * @var \AbcIdType * * @ORM\ManyToOne(targetEntity="AbcIdType") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="id_type", referencedColumnName="id") * }) */ private $idType; /** * @var \AbcMembers * * @ORM\ManyToOne(targetEntity="AbcMembers") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="member", referencedColumnName="id") * }) */ private $member; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set document * * @param string $document * @return AbcMembersPersonalId */ public function setDocument($document) { $this->document = $document; return $this; } /** * Get document * * @return string */ public function getDocument() { return $this->document; } /** * Set createdDate * * @param \DateTime $createdDate * @return AbcMembersPersonalId */ public function setCreatedDate($createdDate) { $this->createdDate = $createdDate; return $this; } /** * Get createdDate * * @return \DateTime */ public function getCreatedDate() { return $this->createdDate; } /** * Set idType * * @param \ABC\PreEnrollmentBundle\Entity\AbcIdType $idType * @return AbcMembersPersonalId */ public function setIdType(\ABC\PreEnrollmentBundle\Entity\AbcIdType $idType = null) { $this->idType = $idType; return $this; } /** * Get idType * * @return \ABC\PreEnrollmentBundle\Entity\AbcIdType */ public function getIdType() { return $this->idType; } /** * Set member * * @param \ABC\PreEnrollmentBundle\Entity\AbcMembers $member * @return AbcMembersPersonalId */ public function setMember(\ABC\PreEnrollmentBundle\Entity\AbcMembers $member = null) { $this->member = $member; return $this; } /** * Get member * * @return \ABC\PreEnrollmentBundle\Entity\AbcMembers */ public function getMember() { return $this->member; } }