From fafe44971c8adf7f932bbe4fe068c14c1fcdc9d3 Mon Sep 17 00:00:00 2001 From: egonzalezf Date: Sun, 28 Jan 2018 16:09:38 -0400 Subject: [PATCH] edicion de crud falta show +bug en edit --- .gitignore | 2 + app/Resources/views/persona/edit.html.twig | 119 +++++++++++++++--- app/Resources/views/persona/index.html.twig | 133 +++++++++++++++------ app/Resources/views/persona/new.html.twig | 118 ++++++++++++++++-- app/Resources/views/persona/show.html.twig | 6 +- .../Controller/personaController.php | 98 ++++++++------- src/UBV/PracticaBundle/Entity/persona.php | 38 +++++- src/UBV/PracticaBundle/Form/personaType.php | 37 +++++- 8 files changed, 434 insertions(+), 117 deletions(-) diff --git a/.gitignore b/.gitignore index 951b549..d8da99c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ /vendor/ /bin/ /composer.phar +/nbproject/private/ +/nbproject/ \ No newline at end of file diff --git a/app/Resources/views/persona/edit.html.twig b/app/Resources/views/persona/edit.html.twig index 10d4c38..0804819 100644 --- a/app/Resources/views/persona/edit.html.twig +++ b/app/Resources/views/persona/edit.html.twig @@ -1,21 +1,106 @@ {% extends 'base.html.twig' %} {% block body %} -

Persona edit

- {{ form_start(edit_form) }} - {{ form_widget(edit_form) }} - - {{ form_end(edit_form) }} - - -{% endblock %} +
+
+
+
+
+
Formulario De Edición
+
+

Datos Personales

+
+
+
+
+
+
+
+
+
+ {{ form_label(edit_form.cedula) }} + {{ form_widget(edit_form.cedula) }} +
+
+ {% if edit_form.cedula.vars.errors[0].message is defined %} + + {{ edit_form.cedula.vars.errors[0].message }} + +
+ {% endif %} +
+
+
+
+ {{ form_label(edit_form.nombre) }} + {{ form_widget(edit_form.nombre) }} + {% if edit_form.nombre.errors[0].message is defined %} + + {{ edit_form.nombre.vars.errors[0].message }} + + {% endif %} +
+
+
+
+ {{ form_label(edit_form.apellido) }} + {{ form_widget(edit_form.apellido) }} + {% if edit_form.apellido.vars.errors[0].message is defined %} + + {{ edit_form.apellido.vars.errors[0].message }} + + {% endif %} +
+
+
+
+
+
+ {{ form_label(edit_form.genero) }} +
+
+ {{ form_widget(edit_form.genero) }} + {% if edit_form.genero.vars.errors[0].message is defined %} + + {{ edit_form.genero.vars.errors[0].message }} + + {% endif %} +
+
+
+
+ {{ form_label(edit_form.direccion) }} + {{ form_widget(edit_form.direccion) }} + {% if edit_form.direccion.vars.errors[0].message is defined %} + + {{ edit_form.direccion.vars.errors[0].message }} + + {% endif %} +
+
+
+
+
+
+
+ {{form_widget(edit_form._token)}} + + + + +   +
+
+
+
+
+
+ +
+
+{% endblock %} \ No newline at end of file diff --git a/app/Resources/views/persona/index.html.twig b/app/Resources/views/persona/index.html.twig index 941fcf7..153ed3d 100644 --- a/app/Resources/views/persona/index.html.twig +++ b/app/Resources/views/persona/index.html.twig @@ -1,47 +1,104 @@ {% extends 'base.html.twig' %} {% block body %} -

Personas list

- - - - - - - - - - - - - +{% for type, flashMessage in app.session.flashbag.all() %} +
+ + {% if flashMessage.title is defined %} + {{ flashMessage.title }} + {{ flashMessage.message }} + {% else %} + {{ type }} + {% endif %} +
+ {% endfor %} +
+
IdNombreApellidoCedulaGeneroDireccionActions
+ + + + + + + + + + + {% for persona in personas %} - - - - - - + + + + + + - - {% endfor %} +
    +    +    +    +
+ + + {% endfor %} -
IDNombreApellidoCedulaGeneroDireccionAcciones
{{ persona.id }}{{ persona.nombre }}{{ persona.apellido }}{{ persona.cedula }}{{ persona.genero }}{{ persona.direccion }}{{ loop.index }}{{ persona.nombre | capitalize}}{{ persona.apellido | capitalize}}{{ persona.cedula }}{{ persona.genero | capitalize}}{{ persona.direccion }} - -
- - + +
+
+ + + + + + + + + {% endblock %} +{% block javascripts %} + {{ parent() }} + +{% endblock javascripts %} \ No newline at end of file diff --git a/app/Resources/views/persona/new.html.twig b/app/Resources/views/persona/new.html.twig index 4988328..66bdb30 100644 --- a/app/Resources/views/persona/new.html.twig +++ b/app/Resources/views/persona/new.html.twig @@ -1,16 +1,108 @@ {% extends 'base.html.twig' %} {% block body %} -

Persona creation

- - {{ form_start(form) }} - {{ form_widget(form) }} - - {{ form_end(form) }} - - -{% endblock %} +
+
+
+
+
+
+
+
+

Formulario De Registro de Persona

+
+ {{ form_start(form, {'attr': {'novalidate': 'novalidate'}, 'action': path('persona_new')}) }} +
+
+
+
+ {{ form_label(form.cedula) }} + {{ form_widget(form.cedula) }} +
+
+ {% if form.cedula.vars.errors[0].message is defined %} + + {{ form.cedula.vars.errors[0].message }} + +
+ {% endif %} +
+
+
+
+ {{ form_label(form.nombre) }} + {{ form_widget(form.nombre) }} + {% if form.nombre.errors[0].message is defined %} + + {{ form.nombre.vars.errors[0].message }} + + {% endif %} +
+
+
+
+ {{ form_label(form.apellido) }} + {{ form_widget(form.apellido) }} + {% if form.apellido.vars.errors[0].message is defined %} + + {{ form.apellido.vars.errors[0].message }} + + {% endif %} +
+
+
+
+
+
+ {{ form_label(form.genero) }} +
+
+ {{ form_widget(form.genero) }} + {% if form.genero.vars.errors[0].message is defined %} + + {{ form.genero.vars.errors[0].message }} + + {% endif %} +
+
+
+
+ {{ form_label(form.direccion) }} + {{ form_widget(form.direccion) }} + {% if form.direccion.vars.errors[0].message is defined %} + + {{ form.direccion.vars.errors[0].message }} + + {% endif %} +
+
+
+
+ +
+
+
+
+ + + + +   +
+
+
+
+
+
+
+ + + + + +{% endblock %} \ No newline at end of file diff --git a/app/Resources/views/persona/show.html.twig b/app/Resources/views/persona/show.html.twig index 02fb744..186cba2 100644 --- a/app/Resources/views/persona/show.html.twig +++ b/app/Resources/views/persona/show.html.twig @@ -39,10 +39,6 @@
  • Edit
  • -
  • - {{ form_start(delete_form) }} - - {{ form_end(delete_form) }} -
  • + {% endblock %} diff --git a/src/UBV/PracticaBundle/Controller/personaController.php b/src/UBV/PracticaBundle/Controller/personaController.php index 25dd72f..1605b2a 100644 --- a/src/UBV/PracticaBundle/Controller/personaController.php +++ b/src/UBV/PracticaBundle/Controller/personaController.php @@ -47,8 +47,14 @@ class personaController extends Controller $em = $this->getDoctrine()->getManager(); $em->persist($persona); $em->flush(); - - return $this->redirectToRoute('persona_show', array('id' => $persona->getId())); + $this->get('session')->getFlashBag()->set( + 'success', array( + 'title' => 'Guardado!', + 'message' => 'Persona Guardado satisfactoriamente.' + ) + ); + + return $this->redirectToRoute('persona_index', array('id' => $persona->getId())); } return $this->render('persona/new.html.twig', array( @@ -65,11 +71,11 @@ class personaController extends Controller */ public function showAction(persona $persona) { - $deleteForm = $this->createDeleteForm($persona); + return $this->render('persona/show.html.twig', array( 'persona' => $persona, - 'delete_form' => $deleteForm->createView(), + )); } @@ -81,56 +87,64 @@ class personaController extends Controller */ public function editAction(Request $request, persona $persona) { - $deleteForm = $this->createDeleteForm($persona); + $editForm = $this->createForm('UBV\PracticaBundle\Form\personaType', $persona); $editForm->handleRequest($request); if ($editForm->isSubmitted() && $editForm->isValid()) { $this->getDoctrine()->getManager()->flush(); - return $this->redirectToRoute('persona_edit', array('id' => $persona->getId())); + $this->get('session')->getFlashBag()->set( + 'success', array( + 'title' => 'Editado!', + 'message' => 'Persona Editado satisfactoriamente.' + ) + ); + + return $this->redirectToRoute('persona_index', array('id' => $persona->getId())); } return $this->render('persona/edit.html.twig', array( 'persona' => $persona, 'edit_form' => $editForm->createView(), - 'delete_form' => $deleteForm->createView(), + )); } - /** + /** * Deletes a persona entity. - * - * @Route("/{id}", name="persona_delete") - * @Method("DELETE") - */ - public function deleteAction(Request $request, persona $persona) - { - $form = $this->createDeleteForm($persona); - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); - $em->remove($persona); - $em->flush(); - } - - return $this->redirectToRoute('persona_index'); - } - - /** - * Creates a form to delete a persona entity. - * - * @param persona $persona The persona entity - * - * @return \Symfony\Component\Form\Form The form - */ - private function createDeleteForm(persona $persona) - { - return $this->createFormBuilder() - ->setAction($this->generateUrl('persona_delete', array('id' => $persona->getId()))) - ->setMethod('DELETE') - ->getForm() - ; - } -} + * + * @Route("/borrar/{id}", name="persona_delete") <--- aqui le defines la ruta que va a tomar--> + * @Method("GET") + */ + public function deleteAction(Request $request, $id) { + $em = $this->getDoctrine()->getManager(); + $entity = $em->getRepository('UBVSurUbvBundle:persona')->Find($id); + $em->remove($entity); + $em->flush(); + + $this->get('session')->getFlashBag()->set( + 'danger', array( + 'title' => 'Eliminado!', + 'message' => 'persona Eliminado satisfactoriamente.' + ) + ); + + return $this->redirectToRoute('persona_index'); + } + + /** + * Creates a form to delete a persona entity. + * + * @param Banco $id The persona entity + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm($id) { + return $this->createFormBuilder() + ->setAction($this->generateUrl('persona_delete', array('id' => $id))) + ->setMethod('DELETE') + ->getForm() + ; + } +} \ No newline at end of file diff --git a/src/UBV/PracticaBundle/Entity/persona.php b/src/UBV/PracticaBundle/Entity/persona.php index 416a93f..bfdf4ce 100644 --- a/src/UBV/PracticaBundle/Entity/persona.php +++ b/src/UBV/PracticaBundle/Entity/persona.php @@ -1,6 +1,8 @@ add('nombre')->add('apellido')->add('cedula')->add('genero')->add('direccion'); + $builder + ->add('nombre', null, array( + 'constraints' => new NotBlank(array('groups' => array('Default'))), + 'label'=>'Nombre', + 'attr' => array('class' => 'form-control','placeholder'=>'Primer Nombre'), + 'label_attr' => array('class' => 'control-label'), + )) + ->add('apellido', null, array( + + 'constraints' => new NotBlank(array('groups' => array('Default'))), + 'label'=>'Apellido', + 'attr' => array('class' => 'form-control','placeholder'=>'Primer Apellido'), + 'label_attr' => array('class' => 'control-label'), + )) + ->add('cedula', null, array( + 'constraints' => new NotBlank(array('groups' => array('Default'))), + 'label'=>'Cedula', + 'attr' => array('class' => 'form-control','placeholder'=>'Ejemplo:18031258'), + 'label_attr' => array('class' => 'control-label'), + )) + + ->add('genero', + 'choice', array( + 'choices' => array( + 'Masculino' => 'Masculino', + 'Femenino' => 'Femenino' + ) + )) + ->add('direccion', null, array( + 'constraints' => new NotBlank(array('groups' => array('Default'))), + 'label'=>'Direccion', + 'attr' => array('class' => 'form-control','placeholder'=>'Direccion completa'), + 'label_attr' => array('class' => 'control-label'))); }/** * {@inheritdoc} */ -- 2.0.0