Commit fafe44971c8adf7f932bbe4fe068c14c1fcdc9d3
1 parent
3213d75b2f
Exists in
feature/pruebas
edicion de crud falta show +bug en edit
Showing
8 changed files
with
434 additions
and
117 deletions
Show diff stats
.gitignore
app/Resources/views/persona/edit.html.twig
1 | 1 | {% extends 'base.html.twig' %} |
2 | 2 | |
3 | 3 | {% block body %} |
4 | - <h1>Persona edit</h1> | |
5 | 4 | |
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('persona_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 %} | |
5 | + <div class="row"> | |
6 | + <div class="col-lg-12"> | |
7 | + <div class="panel panel-default"> | |
8 | + <div class="portlet"> | |
9 | + <div class="portlet-header"> | |
10 | + <div class="caption">Formulario De Edición</div> | |
11 | + </div> | |
12 | + <h3 class="block-heading">Datos Personales</h3> | |
13 | + <div class="form-body pal"> | |
14 | + <div class="row"> | |
15 | + <div class="col-lg-12"> | |
16 | + <form action="{{ path('persona_edit', { 'id': persona.id }) }}" id="form_persona" novalidate method="POST" {{ form_enctype(edit_form)}}> | |
17 | + <div id="informacionPersonal" class="tab-pane fade in active"> | |
18 | + <div class="col-md-12"> | |
19 | + <div class="row"> | |
20 | + <div class="col-md-4"> | |
21 | + <div class="form-group{% if edit_form.cedula.vars.errors[0].message is defined %} has-error{% endif %}"> | |
22 | + {{ form_label(edit_form.cedula) }} | |
23 | + {{ form_widget(edit_form.cedula) }} | |
24 | + </div> | |
25 | + </div> | |
26 | + {% if edit_form.cedula.vars.errors[0].message is defined %} | |
27 | + <span class="help-block"> | |
28 | + {{ edit_form.cedula.vars.errors[0].message }} | |
29 | + </span> | |
30 | + </div> | |
31 | + {% endif %} | |
32 | + </div> | |
33 | + </div> | |
34 | + <div class="col-md-3"> | |
35 | + <div class="form-group{% if edit_form.nombre.vars.errors[0].message is defined %} has-error{% endif %}"> | |
36 | + {{ form_label(edit_form.nombre) }} | |
37 | + {{ form_widget(edit_form.nombre) }} | |
38 | + {% if edit_form.nombre.errors[0].message is defined %} | |
39 | + <span class="help-block"> | |
40 | + {{ edit_form.nombre.vars.errors[0].message }} | |
41 | + </span> | |
42 | + {% endif %} | |
43 | + </div> | |
44 | + </div> | |
45 | + <div class="col-md-3"> | |
46 | + <div class="form-group{% if edit_form.apellido.vars.errors[0].message is defined %} has-error{% endif %}"> | |
47 | + {{ form_label(edit_form.apellido) }} | |
48 | + {{ form_widget(edit_form.apellido) }} | |
49 | + {% if edit_form.apellido.vars.errors[0].message is defined %} | |
50 | + <span class="help-block"> | |
51 | + {{ edit_form.apellido.vars.errors[0].message }} | |
52 | + </span> | |
53 | + {% endif %} | |
54 | + </div> | |
55 | + </div> | |
56 | + <div class="row"> | |
57 | + <div class="col-lg-12"> | |
58 | + <div class="col-md-3"> | |
59 | + <div class="form-group{% if edit_form.genero.vars.errors[0].message is defined %} has-error{% endif %}"> | |
60 | + {{ form_label(edit_form.genero) }} | |
61 | + <div> | |
62 | + </div> | |
63 | + {{ form_widget(edit_form.genero) }} | |
64 | + {% if edit_form.genero.vars.errors[0].message is defined %} | |
65 | + <span class="help-block"> | |
66 | + {{ edit_form.genero.vars.errors[0].message }} | |
67 | + </span> | |
68 | + {% endif %} | |
69 | + </div> | |
70 | + </div> | |
71 | + <div class="col-md-6"> | |
72 | + <div class="form-group{% if edit_form.direccion.vars.errors[0].message is defined %} has-error{% endif %}"> | |
73 | + {{ form_label(edit_form.direccion) }} | |
74 | + {{ form_widget(edit_form.direccion) }} | |
75 | + {% if edit_form.direccion.vars.errors[0].message is defined %} | |
76 | + <span class="help-block"> | |
77 | + {{ edit_form.direccion.vars.errors[0].message }} | |
78 | + </span> | |
79 | + {% endif %} | |
80 | + </div> | |
81 | + </div> | |
82 | + </div> | |
83 | + </div> | |
84 | + <div class="row"> | |
85 | + <div class="col-md-12"> | |
86 | + <div class="form-actions text-right pal"> | |
87 | + {{form_widget(edit_form._token)}} | |
88 | + <a href="{{ path('persona_index') }}"> | |
89 | + <button type="button" class="btn btn-danger"> | |
90 | + Cancelar | |
91 | + </button> | |
92 | + </a> | |
93 | + <button type="submit" class="btn btn-primary"> | |
94 | + Editar | |
95 | + </button> | |
96 | + | |
97 | + </div> | |
98 | + </div> | |
99 | + </div> | |
100 | + </div> | |
101 | + </div> | |
102 | + </div> | |
103 | + </form> | |
104 | + </div> | |
105 | + </div> | |
106 | +{% endblock %} | |
22 | 107 | \ No newline at end of file | ... | ... |
app/Resources/views/persona/index.html.twig
1 | 1 | {% extends 'base.html.twig' %} |
2 | 2 | |
3 | 3 | {% block body %} |
4 | - <h1>Personas list</h1> | |
5 | - | |
6 | - <table> | |
7 | - <thead> | |
8 | - <tr> | |
9 | - <th>Id</th> | |
10 | - <th>Nombre</th> | |
11 | - <th>Apellido</th> | |
12 | - <th>Cedula</th> | |
13 | - <th>Genero</th> | |
14 | - <th>Direccion</th> | |
15 | - <th>Actions</th> | |
16 | - </tr> | |
17 | - </thead> | |
4 | +{% for type, flashMessage in app.session.flashbag.all() %} | |
5 | + <div class="alert alert-{{ type }} fade in"> | |
6 | + <button class="close" data-dismiss="alert" type="button">×</button> | |
7 | + {% if flashMessage.title is defined %} | |
8 | + <strong>{{ flashMessage.title }}</strong> | |
9 | + {{ flashMessage.message }} | |
10 | + {% else %} | |
11 | + {{ type }} | |
12 | + {% endif %} | |
13 | + </div> | |
14 | + {% endfor %} | |
15 | + <div class="row"> | |
16 | + <div class="col-lg-12"> | |
17 | + <div class="portlet-body"> | |
18 | + <div class="table-tools"> | |
19 | + <a href="{{ path('persona_new') }}"> | |
20 | + <button type="button" class="btn btn-red mrs"><i class="fa fa-plus"></i> | |
21 | + Agregar | |
22 | + </button> | |
23 | + </a> | |
24 | + </div> | |
25 | + <div class="table-responsive mtl"> | |
26 | + <table class="table table-striped table-bordered table-hover"> | |
27 | + <thead> | |
28 | + <tr> | |
29 | + <th class="text-center">ID</th> | |
30 | + <th class="text-center">Nombre</th> | |
31 | + <th class="text-center">Apellido</th> | |
32 | + <th class="text-center">Cedula</th> | |
33 | + <th class="text-center">Genero</th> | |
34 | + <th class="text-center">Direccion</th> | |
35 | + <th class="text-center">Acciones</th> | |
36 | + </tr> | |
37 | + </thead> | |
18 | 38 | <tbody> |
19 | 39 | {% for persona in personas %} |
20 | 40 | <tr> |
21 | - <td><a href="{{ path('persona_show', { 'id': persona.id }) }}">{{ persona.id }}</a></td> | |
22 | - <td>{{ persona.nombre }}</td> | |
23 | - <td>{{ persona.apellido }}</td> | |
24 | - <td>{{ persona.cedula }}</td> | |
25 | - <td>{{ persona.genero }}</td> | |
26 | - <td>{{ persona.direccion }}</td> | |
41 | + <td class="text-center"><a href="{{ path('persona_show', { 'id': persona.id }) }}">{{ loop.index }}</a></td> | |
42 | + <td class="text-center">{{ persona.nombre | capitalize}}</td> | |
43 | + <td class="text-center">{{ persona.apellido | capitalize}}</td> | |
44 | + <td class="text-center">{{ persona.cedula }}</td> | |
45 | + <td class="text-center">{{ persona.genero | capitalize}}</td> | |
46 | + <td class="text-center">{{ persona.direccion }}</td> | |
27 | 47 | <td> |
28 | - <ul> | |
29 | - <li> | |
30 | - <a href="{{ path('persona_show', { 'id': persona.id }) }}">show</a> | |
31 | - </li> | |
32 | - <li> | |
33 | - <a href="{{ path('persona_edit', { 'id': persona.id }) }}">edit</a> | |
34 | - </li> | |
35 | - </ul> | |
36 | - </td> | |
37 | - </tr> | |
38 | - {% endfor %} | |
48 | + <ul> | |
49 | + <a href="{{ path('persona_show', { 'id': persona.id }) }}"><span title="Mostrar" class="glyphicon text-info glyphicon-eye-open"></span></a> | |
50 | + <a href="{{ path('persona_edit', { 'id': persona.id }) }}"><span title="Editar" class="glyphicon text-warning glyphicon-edit"></span></a> | |
51 | + <a data-whatever="{{persona.id}}" data-toggle="modal" data-target="#myModal" href="#"><span title="Eliminar" class="glyphicon text-orange glyphicon-trash"></span></a> | |
52 | + </ul> | |
53 | + </td> | |
54 | + </tr> | |
55 | + {% endfor %} | |
39 | 56 | </tbody> |
40 | - </table> | |
41 | - | |
42 | - <ul> | |
43 | - <li> | |
44 | - <a href="{{ path('persona_new') }}">Create a new persona</a> | |
45 | - </li> | |
46 | - </ul> | |
57 | + </table> | |
58 | + </div> | |
59 | + </div> | |
60 | + </div> | |
61 | + </div> | |
62 | + </div> | |
63 | + </div> | |
64 | + </div> | |
65 | + </div> | |
66 | + <!--modal para eliminar --> | |
67 | + <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> | |
68 | + <div class="modal-dialog"> | |
69 | + <div class="modal-content"> | |
70 | + <div class="modal-header"> | |
71 | + <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | |
72 | + <h4 class="modal-title" id="myModalLabel">Eliminar!!!</h4> | |
73 | + </div> | |
74 | + <div class="modal-body"> | |
75 | + <h4>¿ Está seguro de querer eliminar este registro?</h4> | |
76 | + </div> | |
77 | + <div class="modal-footer"> | |
78 | + <a class="btn btn-default" type="button" class="close" data-dismiss="modal" aria-label="Close" >Cancelar</a> | |
79 | + <a class="btn btn-danger" id="borrar" href="#" >Eliminar</a> | |
80 | + </div> | |
81 | + </div> | |
82 | + </div> | |
83 | + </div> | |
84 | + <!--fin del modal--> | |
47 | 85 | {% endblock %} |
86 | +{% block javascripts %} | |
87 | + {{ parent() }} | |
88 | + <script> | |
89 | + $('#myModal').on('show.bs.modal', function (event) { | |
90 | + var button = $(event.relatedTarget) // Button that triggered the modal | |
91 | + var recipient = button.data('whatever') // Extract info from data-* attributes | |
92 | + | |
93 | + // If necessary, you could initiate an AJAX request here (and then do the updating in a callback). | |
94 | + // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead. | |
95 | + var modal = $(this) | |
96 | + var ruta = "{{path('persona_delete', { 'id': "borrar_id" })}}"; | |
97 | + | |
98 | + var borrar = ruta.replace("borrar_id", recipient); | |
99 | + modal.find('#borrar').attr("href", borrar); | |
100 | + | |
101 | + | |
102 | + }); | |
103 | + </script> | |
104 | +{% endblock javascripts %} | |
48 | 105 | \ No newline at end of file | ... | ... |
app/Resources/views/persona/new.html.twig
1 | 1 | {% extends 'base.html.twig' %} |
2 | 2 | |
3 | 3 | {% block body %} |
4 | - <h1>Persona creation</h1> | |
5 | - | |
6 | - {{ form_start(form) }} | |
7 | - {{ form_widget(form) }} | |
8 | - <input type="submit" value="Create" /> | |
9 | - {{ form_end(form) }} | |
10 | - | |
11 | - <ul> | |
12 | - <li> | |
13 | - <a href="{{ path('persona_index') }}">Back to the list</a> | |
14 | - </li> | |
15 | - </ul> | |
16 | -{% endblock %} | |
4 | + <div class "row"> | |
5 | + <div class="panel panel-default"> | |
6 | + <div class="portlet"> | |
7 | + <div class="portlet-header"> | |
8 | + </div> | |
9 | + <div class="form-body pal"> | |
10 | + <div class="row"> | |
11 | + <div class="col-lg-12"> | |
12 | + <h3 class="block-heading">Formulario De Registro de Persona</h3> | |
13 | + <div></div> | |
14 | + {{ form_start(form, {'attr': {'novalidate': 'novalidate'}, 'action': path('persona_new')}) }} | |
15 | + <div id="myTabContent2" class="tab-content"> | |
16 | + <div id="informacionPersonal" class="tab-pane fade in active"> | |
17 | + <div class="col-md-3"> | |
18 | + <div class="form-group{% if form.cedula.vars.errors[0].message is defined %} has-error{% endif %}"> | |
19 | + {{ form_label(form.cedula) }} | |
20 | + {{ form_widget(form.cedula) }} | |
21 | + </div> | |
22 | + </div> | |
23 | + {% if form.cedula.vars.errors[0].message is defined %} | |
24 | + <span class="help-block"> | |
25 | + {{ form.cedula.vars.errors[0].message }} | |
26 | + </span> | |
27 | + </div> | |
28 | + {% endif %} | |
29 | + </div> | |
30 | + </div> | |
31 | + <div class="col-md-3"> | |
32 | + <div class="form-group{% if form.nombre.vars.errors[0].message is defined %} has-error{% endif %}"> | |
33 | + {{ form_label(form.nombre) }} | |
34 | + {{ form_widget(form.nombre) }} | |
35 | + {% if form.nombre.errors[0].message is defined %} | |
36 | + <span class="help-block"> | |
37 | + {{ form.nombre.vars.errors[0].message }} | |
38 | + </span> | |
39 | + {% endif %} | |
40 | + </div> | |
41 | + </div> | |
42 | + <div class="col-md-3"> | |
43 | + <div class="form-group{% if form.apellido.vars.errors[0].message is defined %} has-error{% endif %}"> | |
44 | + {{ form_label(form.apellido) }} | |
45 | + {{ form_widget(form.apellido) }} | |
46 | + {% if form.apellido.vars.errors[0].message is defined %} | |
47 | + <span class="help-block"> | |
48 | + {{ form.apellido.vars.errors[0].message }} | |
49 | + </span> | |
50 | + {% endif %} | |
51 | + </div> | |
52 | + </div> | |
53 | + <div class="row"> | |
54 | + <div class="col-lg-12"> | |
55 | + <div class="col-md-3"> | |
56 | + <div class="form-group{% if form.genero.vars.errors[0].message is defined %} has-error{% endif %}"> | |
57 | + {{ form_label(form.genero) }} | |
58 | + <div> | |
59 | + </div> | |
60 | + {{ form_widget(form.genero) }} | |
61 | + {% if form.genero.vars.errors[0].message is defined %} | |
62 | + <span class="help-block"> | |
63 | + {{ form.genero.vars.errors[0].message }} | |
64 | + </span> | |
65 | + {% endif %} | |
66 | + </div> | |
67 | + </div> | |
68 | + <div class="col-md-6"> | |
69 | + <div class="form-group{% if form.direccion.vars.errors[0].message is defined %} has-error{% endif %}"> | |
70 | + {{ form_label(form.direccion) }} | |
71 | + {{ form_widget(form.direccion) }} | |
72 | + {% if form.direccion.vars.errors[0].message is defined %} | |
73 | + <span class="help-block"> | |
74 | + {{ form.direccion.vars.errors[0].message }} | |
75 | + </span> | |
76 | + {% endif %} | |
77 | + </div> | |
78 | + </div> | |
79 | + </div> | |
80 | + </div> | |
81 | + | |
82 | + </div> | |
83 | + <div class="row"> | |
84 | + <div class="col-md-12"> | |
85 | + <div class="form-actions text-right pal"> | |
86 | + <a href="{{ path('persona_index') }}"> | |
87 | + <button type="button" class="btn btn-danger"> | |
88 | + Cancelar | |
89 | + </button> | |
90 | + </a> | |
91 | + <button type="submit" class="btn btn-primary"> | |
92 | + Guardar | |
93 | + {{ form_end(form)}} | |
94 | + </button> | |
95 | + | |
96 | + </div> | |
97 | + </div> | |
98 | + </div> | |
99 | + </div> | |
100 | + </div> | |
101 | + </div> | |
102 | + </div> | |
103 | + </div> | |
104 | + </div> | |
105 | + </div> | |
106 | + </div> | |
107 | + </div> | |
108 | +{% endblock %} | |
17 | 109 | \ No newline at end of file | ... | ... |
app/Resources/views/persona/show.html.twig
... | ... | @@ -39,10 +39,6 @@ |
39 | 39 | <li> |
40 | 40 | <a href="{{ path('persona_edit', { 'id': persona.id }) }}">Edit</a> |
41 | 41 | </li> |
42 | - <li> | |
43 | - {{ form_start(delete_form) }} | |
44 | - <input type="submit" value="Delete"> | |
45 | - {{ form_end(delete_form) }} | |
46 | - </li> | |
42 | + | |
47 | 43 | </ul> |
48 | 44 | {% endblock %} | ... | ... |
src/UBV/PracticaBundle/Controller/personaController.php
... | ... | @@ -47,8 +47,14 @@ class personaController extends Controller |
47 | 47 | $em = $this->getDoctrine()->getManager(); |
48 | 48 | $em->persist($persona); |
49 | 49 | $em->flush(); |
50 | - | |
51 | - return $this->redirectToRoute('persona_show', array('id' => $persona->getId())); | |
50 | + $this->get('session')->getFlashBag()->set( | |
51 | + 'success', array( | |
52 | + 'title' => 'Guardado!', | |
53 | + 'message' => 'Persona Guardado satisfactoriamente.' | |
54 | + ) | |
55 | + ); | |
56 | + | |
57 | + return $this->redirectToRoute('persona_index', array('id' => $persona->getId())); | |
52 | 58 | } |
53 | 59 | |
54 | 60 | return $this->render('persona/new.html.twig', array( |
... | ... | @@ -65,11 +71,11 @@ class personaController extends Controller |
65 | 71 | */ |
66 | 72 | public function showAction(persona $persona) |
67 | 73 | { |
68 | - $deleteForm = $this->createDeleteForm($persona); | |
74 | + | |
69 | 75 | |
70 | 76 | return $this->render('persona/show.html.twig', array( |
71 | 77 | 'persona' => $persona, |
72 | - 'delete_form' => $deleteForm->createView(), | |
78 | + | |
73 | 79 | )); |
74 | 80 | } |
75 | 81 | |
... | ... | @@ -81,56 +87,64 @@ class personaController extends Controller |
81 | 87 | */ |
82 | 88 | public function editAction(Request $request, persona $persona) |
83 | 89 | { |
84 | - $deleteForm = $this->createDeleteForm($persona); | |
90 | + | |
85 | 91 | $editForm = $this->createForm('UBV\PracticaBundle\Form\personaType', $persona); |
86 | 92 | $editForm->handleRequest($request); |
87 | 93 | |
88 | 94 | if ($editForm->isSubmitted() && $editForm->isValid()) { |
89 | 95 | $this->getDoctrine()->getManager()->flush(); |
90 | 96 | |
91 | - return $this->redirectToRoute('persona_edit', array('id' => $persona->getId())); | |
97 | + $this->get('session')->getFlashBag()->set( | |
98 | + 'success', array( | |
99 | + 'title' => 'Editado!', | |
100 | + 'message' => 'Persona Editado satisfactoriamente.' | |
101 | + ) | |
102 | + ); | |
103 | + | |
104 | + return $this->redirectToRoute('persona_index', array('id' => $persona->getId())); | |
92 | 105 | } |
93 | 106 | |
94 | 107 | return $this->render('persona/edit.html.twig', array( |
95 | 108 | 'persona' => $persona, |
96 | 109 | 'edit_form' => $editForm->createView(), |
97 | - 'delete_form' => $deleteForm->createView(), | |
110 | + | |
98 | 111 | )); |
99 | 112 | } |
100 | 113 | |
101 | - /** | |
114 | + /** | |
102 | 115 | * Deletes a persona entity. |
103 | - * | |
104 | - * @Route("/{id}", name="persona_delete") | |
105 | - * @Method("DELETE") | |
106 | - */ | |
107 | - public function deleteAction(Request $request, persona $persona) | |
108 | - { | |
109 | - $form = $this->createDeleteForm($persona); | |
110 | - $form->handleRequest($request); | |
111 | - | |
112 | - if ($form->isSubmitted() && $form->isValid()) { | |
113 | - $em = $this->getDoctrine()->getManager(); | |
114 | - $em->remove($persona); | |
115 | - $em->flush(); | |
116 | - } | |
117 | - | |
118 | - return $this->redirectToRoute('persona_index'); | |
119 | - } | |
120 | - | |
121 | - /** | |
122 | - * Creates a form to delete a persona entity. | |
123 | - * | |
124 | - * @param persona $persona The persona entity | |
125 | - * | |
126 | - * @return \Symfony\Component\Form\Form The form | |
127 | - */ | |
128 | - private function createDeleteForm(persona $persona) | |
129 | - { | |
130 | - return $this->createFormBuilder() | |
131 | - ->setAction($this->generateUrl('persona_delete', array('id' => $persona->getId()))) | |
132 | - ->setMethod('DELETE') | |
133 | - ->getForm() | |
134 | - ; | |
135 | - } | |
136 | -} | |
116 | + * | |
117 | + * @Route("/borrar/{id}", name="persona_delete") <--- aqui le defines la ruta que va a tomar--> | |
118 | + * @Method("GET") | |
119 | + */ | |
120 | + public function deleteAction(Request $request, $id) { | |
121 | + $em = $this->getDoctrine()->getManager(); | |
122 | + $entity = $em->getRepository('UBVSurUbvBundle:persona')->Find($id); | |
123 | + $em->remove($entity); | |
124 | + $em->flush(); | |
125 | + | |
126 | + $this->get('session')->getFlashBag()->set( | |
127 | + 'danger', array( | |
128 | + 'title' => 'Eliminado!', | |
129 | + 'message' => 'persona Eliminado satisfactoriamente.' | |
130 | + ) | |
131 | + ); | |
132 | + | |
133 | + return $this->redirectToRoute('persona_index'); | |
134 | + } | |
135 | + | |
136 | + /** | |
137 | + * Creates a form to delete a persona entity. | |
138 | + * | |
139 | + * @param Banco $id The persona entity | |
140 | + * | |
141 | + * @return \Symfony\Component\Form\Form The form | |
142 | + */ | |
143 | + private function createDeleteForm($id) { | |
144 | + return $this->createFormBuilder() | |
145 | + ->setAction($this->generateUrl('persona_delete', array('id' => $id))) | |
146 | + ->setMethod('DELETE') | |
147 | + ->getForm() | |
148 | + ; | |
149 | + } | |
150 | +} | |
137 | 151 | \ No newline at end of file | ... | ... |
src/UBV/PracticaBundle/Entity/persona.php
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace UBV\PracticaBundle\Entity; |
4 | +use Doctrine\Common\Collections\ArrayCollection; | |
5 | +use Symfony\Component\Validator\Constraints as Assert; | |
4 | 6 | |
5 | 7 | use Doctrine\ORM\Mapping as ORM; |
6 | 8 | |
... | ... | @@ -23,12 +25,36 @@ class persona |
23 | 25 | |
24 | 26 | /** |
25 | 27 | * @var string |
26 | - * | |
28 | + * @Assert\NotNull(message= "Por favor introduzca su Nombre", groups={"Default"}) | |
29 | + * @Assert\NotBlank( message= "Por favor introduzca Nombre valido Valido", groups={"Default"}) | |
30 | + * @Assert\Length( | |
31 | + * min = 2, | |
32 | + * max = 45, | |
33 | + * minMessage = "Tu Nombre debe tener como minimo {{ limit }} letras", | |
34 | + * maxMessage = "Tu Nombre no debe exceder de {{ limit }} letras" | |
35 | + * ) | |
36 | + * @Assert\Regex( | |
37 | + * pattern="/\d/", | |
38 | + * match=false, | |
39 | + * message="Tu Nombre no debe contener numeros" | |
40 | + *) | |
27 | 41 | * @ORM\Column(name="nombre", type="string", length=50) |
28 | 42 | */ |
29 | 43 | private $nombre; |
30 | 44 | |
31 | 45 | /** |
46 | + * @Assert\NotNull(message= "Por favor introduzca su Apellido", groups={"Default"}) | |
47 | + * @Assert\NotBlank( message= "Por favor introduzca Apellido valido Valido", groups={"Default"}) | |
48 | + * @Assert\Length( | |
49 | + * min = 2, | |
50 | + * max = 45, | |
51 | + * minMessage = "Tu Apellido debe tener como minimo {{ limit }} letras", | |
52 | + * maxMessage = "Tu Apellido no debe exceder de {{ limit }} letras" | |
53 | + * ) | |
54 | + * @Assert\Regex( | |
55 | + * pattern="/\d/", | |
56 | + * match=false, | |
57 | + * message="Tu Apellido no debe contener numeros") | |
32 | 58 | * @var string |
33 | 59 | * |
34 | 60 | * @ORM\Column(name="apellido", type="string", length=50) |
... | ... | @@ -36,6 +62,14 @@ class persona |
36 | 62 | private $apellido; |
37 | 63 | |
38 | 64 | /** |
65 | + *@Assert\NotNull(message= "Por favor introduzca un numero de Cedula", groups={"Default"}) | |
66 | + *@Assert\NotBlank( message= "Por favor introduzca un numero de Cedula Valido", groups={"Default"}) | |
67 | + *@Assert\Length( | |
68 | + * min = 7, | |
69 | + * max = 12, | |
70 | + * minMessage = "El numero de Cedula debe tener como minimo {{ limit }} numeros", | |
71 | + * maxMessage = "El numero de Cedula no debe exceder de {{ limit }} numeros" | |
72 | + * ) | |
39 | 73 | * @var int |
40 | 74 | * |
41 | 75 | * @ORM\Column(name="cedula", type="integer", unique=true) |
... | ... | @@ -43,6 +77,7 @@ class persona |
43 | 77 | private $cedula; |
44 | 78 | |
45 | 79 | /** |
80 | + * @Assert\Type(type="string", message="El valor {{ value }} no es valido {{ type }}.") | |
46 | 81 | * @var string |
47 | 82 | * |
48 | 83 | * @ORM\Column(name="genero", type="string", length=20) |
... | ... | @@ -50,6 +85,7 @@ class persona |
50 | 85 | private $genero; |
51 | 86 | |
52 | 87 | /** |
88 | + * @Assert\Type(type="string", message="El valor {{ value }} no es valido {{ type }}.") | |
53 | 89 | * @var string |
54 | 90 | * |
55 | 91 | * @ORM\Column(name="direccion", type="string", length=255) | ... | ... |
src/UBV/PracticaBundle/Form/personaType.php
... | ... | @@ -5,6 +5,9 @@ namespace UBV\PracticaBundle\Form; |
5 | 5 | use Symfony\Component\Form\AbstractType; |
6 | 6 | use Symfony\Component\Form\FormBuilderInterface; |
7 | 7 | use Symfony\Component\OptionsResolver\OptionsResolver; |
8 | +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |
9 | +use Symfony\Component\Validator\Constraints\NotBlank; | |
10 | +use Symfony\Component\Validator\Constraints\Length; | |
8 | 11 | |
9 | 12 | class personaType extends AbstractType |
10 | 13 | { |
... | ... | @@ -13,7 +16,39 @@ class personaType extends AbstractType |
13 | 16 | */ |
14 | 17 | public function buildForm(FormBuilderInterface $builder, array $options) |
15 | 18 | { |
16 | - $builder->add('nombre')->add('apellido')->add('cedula')->add('genero')->add('direccion'); | |
19 | + $builder | |
20 | + ->add('nombre', null, array( | |
21 | + 'constraints' => new NotBlank(array('groups' => array('Default'))), | |
22 | + 'label'=>'Nombre', | |
23 | + 'attr' => array('class' => 'form-control','placeholder'=>'Primer Nombre'), | |
24 | + 'label_attr' => array('class' => 'control-label'), | |
25 | + )) | |
26 | + ->add('apellido', null, array( | |
27 | + | |
28 | + 'constraints' => new NotBlank(array('groups' => array('Default'))), | |
29 | + 'label'=>'Apellido', | |
30 | + 'attr' => array('class' => 'form-control','placeholder'=>'Primer Apellido'), | |
31 | + 'label_attr' => array('class' => 'control-label'), | |
32 | + )) | |
33 | + ->add('cedula', null, array( | |
34 | + 'constraints' => new NotBlank(array('groups' => array('Default'))), | |
35 | + 'label'=>'Cedula', | |
36 | + 'attr' => array('class' => 'form-control','placeholder'=>'Ejemplo:18031258'), | |
37 | + 'label_attr' => array('class' => 'control-label'), | |
38 | + )) | |
39 | + | |
40 | + ->add('genero', | |
41 | + 'choice', array( | |
42 | + 'choices' => array( | |
43 | + 'Masculino' => 'Masculino', | |
44 | + 'Femenino' => 'Femenino' | |
45 | + ) | |
46 | + )) | |
47 | + ->add('direccion', null, array( | |
48 | + 'constraints' => new NotBlank(array('groups' => array('Default'))), | |
49 | + 'label'=>'Direccion', | |
50 | + 'attr' => array('class' => 'form-control','placeholder'=>'Direccion completa'), | |
51 | + 'label_attr' => array('class' => 'control-label'))); | |
17 | 52 | }/** |
18 | 53 | * {@inheritdoc} |
19 | 54 | */ | ... | ... |