Last active
September 28, 2015 19:02
-
-
Save JuanLuisGarciaBorrego/deacce14aa2c5c5e701a to your computer and use it in GitHub Desktop.
Mostrar un formulario para cada registro de una entidad en la misma vista con Symfony2. Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @Route("/formularios-equipos", name="formulariosEquipos") | |
*/ | |
public function formulariosEquiposAction() | |
{ | |
$equipos = $this->getDoctrine()->getManager()->getRepository('AppBundle:Equipo')->findAll(); | |
$forms = []; //creo una variable tipo array. | |
foreach($equipos as $equipo) { | |
$forms[] = $this->createForm(new EquipoType(), $equipo); | |
} | |
$formsRender = []; | |
foreach($forms as $form) { | |
$formsRender[] = $form->createView(); | |
} | |
return $this->render('default/crear.html.twig', array( | |
'formsRender' => $formsRender | |
)); | |
} | |
/** | |
* @Route("/{id}/formulario-individual", name="formularioIndividual") | |
*/ | |
public function formularioIndividualAction(Equipo $equipo, Request $request) | |
{ | |
$form = $this->createForm(new EquipoType(), $equipo); | |
$form->handleRequest($request); | |
if ($form->isValid()) { | |
$em = $this->getDoctrine()->getManager(); | |
$em->persist($equipo); | |
$em->flush(); | |
return $this->redirectToRoute('homepage'); | |
} | |
return $this->redirectToRoute('formulariosEquipos'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment