Código PHP:
public functionContactoAction($id)
{
$em = $this->getDoctrine()->getManager();
$contacts = new AbcMembersContacts();
$form = $this->createCreateForm($contacts);
return $this->render('MyBundle:Member:Contacto.html.twig',
array(
'member' => $student,
'form' => $form->createView(),
));
}
private function createCreateForm(Members $entity)
{
$form = $this->createForm(new MembersType(), $entity, array(
'action' => $this->generateUrl('contact_create', array('id'=>$entity->getMember()->getId())),
'method' => 'POST',
));
$form->add('save', 'submit', array('label' => 'Save'));
return $form;
}
/**
* @Route("/{id}/create", name="contact_create")
* @Method("POST")
* @Template("MyBundle:Member:Contacto.html.twig")
*/
public function createContactofStudentAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$contacts = new AbcMembersContacts();
$form = $this->createCreateForm($contacts);
$form->handleRequest($request);
...
$em->persist($contacts);
$em->flush();