Commit e46fab24a3b876a8d06ba455dbefecf68f062139
1 parent
8c45a84511
Exists in
feature/jacqueline
inicializacion de proyecto,modificacion platillas con boostrap,visualizar formulario
Showing
9 changed files
with
534 additions
and
0 deletions
Show diff stats
app/Resources/views/usuario/edit.html.twig
... | ... | @@ -0,0 +1,21 @@ |
1 | +{% extends 'base.html.twig' %} | |
2 | + | |
3 | +{% block body %} | |
4 | + <h1>Usuario edit</h1> | |
5 | + | |
6 | + {{ form_start(edit_form) }} | |
7 | + {{ form_widget(edit_form) }} | |
8 | + <input type="submit" value="Edit" /> | |
9 | + {{ form_end(edit_form) }} | |
10 | + | |
11 | + <ul> | |
12 | + <li> | |
13 | + <a href="{{ path('usuario_index') }}">Back to the list</a> | |
14 | + </li> | |
15 | + <li> | |
16 | + {{ form_start(delete_form) }} | |
17 | + <input type="submit" value="Delete"> | |
18 | + {{ form_end(delete_form) }} | |
19 | + </li> | |
20 | + </ul> | |
21 | +{% endblock %} | ... | ... |
app/Resources/views/usuario/index.html.twig
... | ... | @@ -0,0 +1,44 @@ |
1 | +{% extends 'base.html.twig' %} | |
2 | + | |
3 | +{% block body %} | |
4 | + <h1>Usuarios list</h1> | |
5 | + | |
6 | + | |
7 | + | |
8 | +<table class="table table-bordered"> | |
9 | + <thead> | |
10 | + <tr> | |
11 | + <th>Id</th> | |
12 | + <th>Nombre</th> | |
13 | + <th>Apellido</th> | |
14 | + <th>Cedula</th> | |
15 | + <th>Edad</th> | |
16 | + <th>Actions</th> | |
17 | + </tr> | |
18 | + </thead> | |
19 | + <tbody> | |
20 | + {% for usuario in usuarios %} | |
21 | + <tr> | |
22 | + <td><a href="{{ path('usuario_show', { 'id': usuario.id }) }}">{{ usuario.id }}</a></td> | |
23 | + <td>{{ usuario.nombre }}</td> | |
24 | + <td>{{ usuario.apellido }}</td> | |
25 | + <td>{{ usuario.cedula }}</td> | |
26 | + <td>{{ usuario.edad }}</td> | |
27 | + <td> | |
28 | + <ul> | |
29 | + <button class="btn btn-default" type="submit"><a href="{{ path('usuario_show', { 'id': usuario.id }) }}">show</a></button><br> | |
30 | + <button type="button" class="btn btn-primary"><a href="{{ path('usuario_show', { 'id': usuario.id }) }}">show</a></button> | |
31 | + | |
32 | + </ul> | |
33 | + </td> | |
34 | + </tr> | |
35 | + {% endfor %} | |
36 | + </tbody> | |
37 | + </table> | |
38 | + | |
39 | + <ul> | |
40 | + <li> | |
41 | + <a href="{{ path('usuario_new') }}">Create a new usuario</a> | |
42 | + </li> | |
43 | + </ul> | |
44 | +{% endblock %} | ... | ... |
app/Resources/views/usuario/new.html.twig
... | ... | @@ -0,0 +1,26 @@ |
1 | +{% extends 'base.html.twig' %} | |
2 | + | |
3 | +{% block body %} | |
4 | + <h1>Usuario creation</h1> | |
5 | + | |
6 | + {{ form_start(form) }} | |
7 | + {{ form_row(form.nombre) }} | |
8 | + {{ form_row(form.apellido) }} | |
9 | + {{ form_row(form.cedula) }} | |
10 | + {{ form_row(form.edad) }} | |
11 | + {{ form_widget(form) }} | |
12 | + <input type="submit" value="Create" /> | |
13 | + {{ form_end(form) }} | |
14 | + {% block form_row %} | |
15 | + <div class="form_row"> | |
16 | + | |
17 | + | |
18 | + {{ form_widget(form) }} | |
19 | + </div> | |
20 | +{% endblock form_row %} | |
21 | + <ul> | |
22 | + <li> | |
23 | + <a href="{{ path('usuario_index') }}">Back to the list</a> | |
24 | + </li> | |
25 | + </ul> | |
26 | +{% endblock %} | ... | ... |
app/Resources/views/usuario/show.html.twig
... | ... | @@ -0,0 +1,44 @@ |
1 | +{% extends 'base.html.twig' %} | |
2 | + | |
3 | +{% block body %} | |
4 | + <h1>Usuario</h1> | |
5 | + | |
6 | + <table> | |
7 | + <tbody> | |
8 | + <tr> | |
9 | + <th>Id</th> | |
10 | + <td>{{ usuario.id }}</td> | |
11 | + </tr> | |
12 | + <tr> | |
13 | + <th>Nombre</th> | |
14 | + <td>{{ usuario.nombre }}</td> | |
15 | + </tr> | |
16 | + <tr> | |
17 | + <th>Apellido</th> | |
18 | + <td>{{ usuario.apellido }}</td> | |
19 | + </tr> | |
20 | + <tr> | |
21 | + <th>Cedula</th> | |
22 | + <td>{{ usuario.cedula }}</td> | |
23 | + </tr> | |
24 | + <tr> | |
25 | + <th>Edad</th> | |
26 | + <td>{{ usuario.edad }}</td> | |
27 | + </tr> | |
28 | + </tbody> | |
29 | + </table> | |
30 | + | |
31 | + <ul> | |
32 | + <li> | |
33 | + <a href="{{ path('usuario_index') }}">Back to the list</a> | |
34 | + </li> | |
35 | + <li> | |
36 | + <a href="{{ path('usuario_edit', { 'id': usuario.id }) }}">Edit</a> | |
37 | + </li> | |
38 | + <li> | |
39 | + {{ form_start(delete_form) }} | |
40 | + <input type="submit" value="Delete"> | |
41 | + {{ form_end(delete_form) }} | |
42 | + </li> | |
43 | + </ul> | |
44 | +{% endblock %} | ... | ... |
src/UBV/PracticaBundle/Controller/usuarioController.php
... | ... | @@ -0,0 +1,136 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace UBV\PracticaBundle\Controller; | |
4 | + | |
5 | +use UBV\PracticaBundle\Entity\usuario; | |
6 | +use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
7 | +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | |
8 | +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request; | |
9 | + | |
10 | +/** | |
11 | + * Usuario controller. | |
12 | + * | |
13 | + * @Route("usuario") | |
14 | + */ | |
15 | +class usuarioController extends Controller | |
16 | +{ | |
17 | + /** | |
18 | + * Lists all usuario entities. | |
19 | + * | |
20 | + * @Route("/", name="usuario_index") | |
21 | + * @Method("GET") | |
22 | + */ | |
23 | + public function indexAction() | |
24 | + { | |
25 | + $em = $this->getDoctrine()->getManager(); | |
26 | + | |
27 | + $usuarios = $em->getRepository('UBVPracticaBundle:usuario')->findAll(); | |
28 | + | |
29 | + return $this->render('usuario/index.html.twig', array( | |
30 | + 'usuarios' => $usuarios, | |
31 | + )); | |
32 | + } | |
33 | + | |
34 | + /** | |
35 | + * Creates a new usuario entity. | |
36 | + * | |
37 | + * @Route("/new", name="usuario_new") | |
38 | + * @Method({"GET", "POST"}) | |
39 | + */ | |
40 | + public function newAction(Request $request) | |
41 | + { | |
42 | + $usuario = new Usuario(); | |
43 | + $form = $this->createForm('UBV\PracticaBundle\Form\usuarioType', $usuario); | |
44 | + $form->handleRequest($request); | |
45 | + | |
46 | + if ($form->isSubmitted() && $form->isValid()) { | |
47 | + $em = $this->getDoctrine()->getManager(); | |
48 | + $em->persist($usuario); | |
49 | + $em->flush(); | |
50 | + | |
51 | + return $this->redirectToRoute('usuario_show', array('id' => $usuario->getId())); | |
52 | + } | |
53 | + | |
54 | + return $this->render('usuario/new.html.twig', array( | |
55 | + 'usuario' => $usuario, | |
56 | + 'form' => $form->createView(), | |
57 | + )); | |
58 | + } | |
59 | + | |
60 | + /** | |
61 | + * Finds and displays a usuario entity. | |
62 | + * | |
63 | + * @Route("/{id}", name="usuario_show") | |
64 | + * @Method("GET") | |
65 | + */ | |
66 | + public function showAction(usuario $usuario) | |
67 | + { | |
68 | + $deleteForm = $this->createDeleteForm($usuario); | |
69 | + | |
70 | + return $this->render('usuario/show.html.twig', array( | |
71 | + 'usuario' => $usuario, | |
72 | + 'delete_form' => $deleteForm->createView(), | |
73 | + )); | |
74 | + } | |
75 | + | |
76 | + /** | |
77 | + * Displays a form to edit an existing usuario entity. | |
78 | + * | |
79 | + * @Route("/{id}/edit", name="usuario_edit") | |
80 | + * @Method({"GET", "POST"}) | |
81 | + */ | |
82 | + public function editAction(Request $request, usuario $usuario) | |
83 | + { | |
84 | + $deleteForm = $this->createDeleteForm($usuario); | |
85 | + $editForm = $this->createForm('UBV\PracticaBundle\Form\usuarioType', $usuario); | |
86 | + $editForm->handleRequest($request); | |
87 | + | |
88 | + if ($editForm->isSubmitted() && $editForm->isValid()) { | |
89 | + $this->getDoctrine()->getManager()->flush(); | |
90 | + | |
91 | + return $this->redirectToRoute('usuario_edit', array('id' => $usuario->getId())); | |
92 | + } | |
93 | + | |
94 | + return $this->render('usuario/edit.html.twig', array( | |
95 | + 'usuario' => $usuario, | |
96 | + 'edit_form' => $editForm->createView(), | |
97 | + 'delete_form' => $deleteForm->createView(), | |
98 | + )); | |
99 | + } | |
100 | + | |
101 | + /** | |
102 | + * Deletes a usuario entity. | |
103 | + * | |
104 | + * @Route("/{id}", name="usuario_delete") | |
105 | + * @Method("DELETE") | |
106 | + */ | |
107 | + public function deleteAction(Request $request, usuario $usuario) | |
108 | + { | |
109 | + $form = $this->createDeleteForm($usuario); | |
110 | + $form->handleRequest($request); | |
111 | + | |
112 | + if ($form->isSubmitted() && $form->isValid()) { | |
113 | + $em = $this->getDoctrine()->getManager(); | |
114 | + $em->remove($usuario); | |
115 | + $em->flush(); | |
116 | + } | |
117 | + | |
118 | + return $this->redirectToRoute('usuario_index'); | |
119 | + } | |
120 | + | |
121 | + /** | |
122 | + * Creates a form to delete a usuario entity. | |
123 | + * | |
124 | + * @param usuario $usuario The usuario entity | |
125 | + * | |
126 | + * @return \Symfony\Component\Form\Form The form | |
127 | + */ | |
128 | + private function createDeleteForm(usuario $usuario) | |
129 | + { | |
130 | + return $this->createFormBuilder() | |
131 | + ->setAction($this->generateUrl('usuario_delete', array('id' => $usuario->getId()))) | |
132 | + ->setMethod('DELETE') | |
133 | + ->getForm() | |
134 | + ; | |
135 | + } | |
136 | +} | ... | ... |
src/UBV/PracticaBundle/Entity/usuario.php
... | ... | @@ -0,0 +1,159 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace UBV\PracticaBundle\Entity; | |
4 | + | |
5 | +use Doctrine\ORM\Mapping as ORM; | |
6 | + | |
7 | +/** | |
8 | + * usuario | |
9 | + * | |
10 | + * @ORM\Table(name="usuario") | |
11 | + * @ORM\Entity(repositoryClass="UBV\PracticaBundle\Repository\usuarioRepository") | |
12 | + */ | |
13 | +class usuario | |
14 | +{ | |
15 | + /** | |
16 | + * @var int | |
17 | + * | |
18 | + * @ORM\Column(name="id", type="integer") | |
19 | + * @ORM\Id | |
20 | + * @ORM\GeneratedValue(strategy="AUTO") | |
21 | + */ | |
22 | + private $id; | |
23 | + | |
24 | + /** | |
25 | + * @var string | |
26 | + * | |
27 | + * @ORM\Column(name="nombre", type="string", length=50) | |
28 | + */ | |
29 | + private $nombre; | |
30 | + | |
31 | + /** | |
32 | + * @var string | |
33 | + * | |
34 | + * @ORM\Column(name="apellido", type="string", length=50) | |
35 | + */ | |
36 | + private $apellido; | |
37 | + | |
38 | + /** | |
39 | + * @var int | |
40 | + * | |
41 | + * @ORM\Column(name="cedula", type="integer", unique=true) | |
42 | + */ | |
43 | + private $cedula; | |
44 | + | |
45 | + /** | |
46 | + * @var int | |
47 | + * | |
48 | + * @ORM\Column(name="edad", type="integer") | |
49 | + */ | |
50 | + private $edad; | |
51 | + | |
52 | + | |
53 | + /** | |
54 | + * Get id | |
55 | + * | |
56 | + * @return int | |
57 | + */ | |
58 | + public function getId() | |
59 | + { | |
60 | + return $this->id; | |
61 | + } | |
62 | + | |
63 | + /** | |
64 | + * Set nombre | |
65 | + * | |
66 | + * @param string $nombre | |
67 | + * | |
68 | + * @return usuario | |
69 | + */ | |
70 | + public function setNombre($nombre) | |
71 | + { | |
72 | + $this->nombre = $nombre; | |
73 | + | |
74 | + return $this; | |
75 | + } | |
76 | + | |
77 | + /** | |
78 | + * Get nombre | |
79 | + * | |
80 | + * @return string | |
81 | + */ | |
82 | + public function getNombre() | |
83 | + { | |
84 | + return $this->nombre; | |
85 | + } | |
86 | + | |
87 | + /** | |
88 | + * Set apellido | |
89 | + * | |
90 | + * @param string $apellido | |
91 | + * | |
92 | + * @return usuario | |
93 | + */ | |
94 | + public function setApellido($apellido) | |
95 | + { | |
96 | + $this->apellido = $apellido; | |
97 | + | |
98 | + return $this; | |
99 | + } | |
100 | + | |
101 | + /** | |
102 | + * Get apellido | |
103 | + * | |
104 | + * @return string | |
105 | + */ | |
106 | + public function getApellido() | |
107 | + { | |
108 | + return $this->apellido; | |
109 | + } | |
110 | + | |
111 | + /** | |
112 | + * Set cedula | |
113 | + * | |
114 | + * @param integer $cedula | |
115 | + * | |
116 | + * @return usuario | |
117 | + */ | |
118 | + public function setCedula($cedula) | |
119 | + { | |
120 | + $this->cedula = $cedula; | |
121 | + | |
122 | + return $this; | |
123 | + } | |
124 | + | |
125 | + /** | |
126 | + * Get cedula | |
127 | + * | |
128 | + * @return int | |
129 | + */ | |
130 | + public function getCedula() | |
131 | + { | |
132 | + return $this->cedula; | |
133 | + } | |
134 | + | |
135 | + /** | |
136 | + * Set edad | |
137 | + * | |
138 | + * @param integer $edad | |
139 | + * | |
140 | + * @return usuario | |
141 | + */ | |
142 | + public function setEdad($edad) | |
143 | + { | |
144 | + $this->edad = $edad; | |
145 | + | |
146 | + return $this; | |
147 | + } | |
148 | + | |
149 | + /** | |
150 | + * Get edad | |
151 | + * | |
152 | + * @return int | |
153 | + */ | |
154 | + public function getEdad() | |
155 | + { | |
156 | + return $this->edad; | |
157 | + } | |
158 | +} | |
159 | + | ... | ... |
src/UBV/PracticaBundle/Form/usuarioType.php
... | ... | @@ -0,0 +1,36 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace UBV\PracticaBundle\Form; | |
4 | + | |
5 | +use Symfony\Component\Form\AbstractType; | |
6 | +use Symfony\Component\Form\FormBuilderInterface; | |
7 | +use Symfony\Component\OptionsResolver\OptionsResolver; | |
8 | + | |
9 | +class usuarioType extends AbstractType | |
10 | +{ | |
11 | + /** | |
12 | + * {@inheritdoc} | |
13 | + */ | |
14 | + public function buildForm(FormBuilderInterface $builder, array $options) | |
15 | + { | |
16 | + $builder->add('nombre')->add('apellido')->add('cedula')->add('edad'); | |
17 | + }/** | |
18 | + * {@inheritdoc} | |
19 | + */ | |
20 | + public function configureOptions(OptionsResolver $resolver) | |
21 | + { | |
22 | + $resolver->setDefaults(array( | |
23 | + 'data_class' => 'UBV\PracticaBundle\Entity\usuario' | |
24 | + )); | |
25 | + } | |
26 | + | |
27 | + /** | |
28 | + * {@inheritdoc} | |
29 | + */ | |
30 | + public function getBlockPrefix() | |
31 | + { | |
32 | + return 'ubv_practicabundle_usuario'; | |
33 | + } | |
34 | + | |
35 | + | |
36 | +} | ... | ... |
src/UBV/PracticaBundle/Repository/usuarioRepository.php
... | ... | @@ -0,0 +1,13 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace UBV\PracticaBundle\Repository; | |
4 | + | |
5 | +/** | |
6 | + * usuarioRepository | |
7 | + * | |
8 | + * This class was generated by the Doctrine ORM. Add your own custom | |
9 | + * repository methods below. | |
10 | + */ | |
11 | +class usuarioRepository extends \Doctrine\ORM\EntityRepository | |
12 | +{ | |
13 | +} | ... | ... |
src/UBV/PracticaBundle/Tests/Controller/usuarioControllerTest.php
... | ... | @@ -0,0 +1,55 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace UBV\PracticaBundle\Tests\Controller; | |
4 | + | |
5 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | |
6 | + | |
7 | +class usuarioControllerTest extends WebTestCase | |
8 | +{ | |
9 | + /* | |
10 | + public function testCompleteScenario() | |
11 | + { | |
12 | + // Create a new client to browse the application | |
13 | + $client = static::createClient(); | |
14 | + | |
15 | + // Create a new entry in the database | |
16 | + $crawler = $client->request('GET', '/usuario/'); | |
17 | + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /usuario/"); | |
18 | + $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); | |
19 | + | |
20 | + // Fill in the form and submit it | |
21 | + $form = $crawler->selectButton('Create')->form(array( | |
22 | + 'ubv_practicabundle_usuario[field_name]' => 'Test', | |
23 | + // ... other fields to fill | |
24 | + )); | |
25 | + | |
26 | + $client->submit($form); | |
27 | + $crawler = $client->followRedirect(); | |
28 | + | |
29 | + // Check data in the show view | |
30 | + $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); | |
31 | + | |
32 | + // Edit the entity | |
33 | + $crawler = $client->click($crawler->selectLink('Edit')->link()); | |
34 | + | |
35 | + $form = $crawler->selectButton('Update')->form(array( | |
36 | + 'ubv_practicabundle_usuario[field_name]' => 'Foo', | |
37 | + // ... other fields to fill | |
38 | + )); | |
39 | + | |
40 | + $client->submit($form); | |
41 | + $crawler = $client->followRedirect(); | |
42 | + | |
43 | + // Check the element contains an attribute with value equals "Foo" | |
44 | + $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); | |
45 | + | |
46 | + // Delete the entity | |
47 | + $client->submit($crawler->selectButton('Delete')->form()); | |
48 | + $crawler = $client->followRedirect(); | |
49 | + | |
50 | + // Check the entity has been delete on the list | |
51 | + $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); | |
52 | + } | |
53 | + | |
54 | + */ | |
55 | +} | ... | ... |