Bonjour,
Je suis en train de travailler sur une recherche d'élève en fonction de leur nom et prénom mais j’aurais aimé que cette recherche s'actualise en même temps que l'utilisateur saisie soit le nom soit le prénom je qu'il faut utiliser de l'ajax mais avec symfony 2 je ne suis pas arrivé si vous pouviez m'aider merci beaucoup !
Voici mon controller :
Mon routeur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 <?php namespace LGB\BourseLivresBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use LGB\BourseLivresBundle\Form\EleveRechercheType; use LGB\BourseLivresBundle\Form\EleveType; use LGB\BourseLivresBundle\Form\EditType; // Entity // use LGB\BourseLivresBundle\Entity\Eleve; class VenteController extends Controller { public function indexAction() { $eleve = new Eleve; $form = $this->createForm(new EleveRechercheType, $eleve); $request = $this->get('request'); if( $request->getMethod() == 'POST' ) { $form->bindRequest($request); if( $form->isValid() ) { $em = $this->getDoctrine()->getEntityManager(); $nom = $eleve->getNom(); $prenom = $eleve->getPrenom(); $dates = $eleve->getdateNaissance(); $query = $this->getDoctrine()->getEntityManager()->createQuery("SELECT e.ideleve, e.nom, e.prenom, e.dateNaissance, a.nom AS NomResponsable, a.prenom AS PrenomResponsable FROM LGBBourseLivresBundle:Eleve e, LGBBourseLivresBundle:Parents a WHERE e.nom LIKE '%$nom%' AND e.prenom LIKE '%$prenom%' AND e.parentparent = a.idparent ORDER BY e.ideleve"); $resultats = $query->getResult(); $searchEleve = array('nom' => 'test' ); return $this->container->get('templating')->renderResponse('LGBBourseLivresBundle:Vente:home.html.twig', array('form' => $form->createView(), 'resultats' => $resultats)); } } return $this->container->get('templating')->renderResponse('LGBBourseLivresBundle:Vente:home.html.twig', array('form' => $form->createView(), 'resultats' => NULL)); }
Template :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 LGBBourseLivresBundle_home_vente: pattern: /vente/ defaults: { _controller: LGBBourseLivresBundle:Vente:index}
Si vous pouviez me donner un coup de pouce ça serait vraiment sympa merci !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 {% extends "LGBBourseLivresBundle:Vente:layout.html.twig" %} {% block title %}{{ parent() }} - Accueil{% endblock %} {% block body %} <div> <h1><img alt="" src="{{ asset('bundles/lgbbourselivres/images/student.png') }}">RECHERCHER UN ÉLÈVE</h1> <p style="text-align:center;"> </p> <div style="text-align:left"> <form id="form_eleve" method="post" {{ form_enctype(form) }}> <div class="error"> {{ form_errors(form) }} </div> <table> <tr> <td>{{ form_label(form.nom, "Nom :") }}</td> <td>{{ form_label(form.prenom, "Prénom :") }}</td> <!-- <td>{{ form_label(form.dateNaissance, "Date de naissance :") }}</td> --> <td></td> </tr> <tr> <td> {{ form_errors(form.nom) }} {{ form_widget(form.nom) }} </td> <td> {{ form_errors(form.prenom) }} {{ form_widget(form.prenom) }} </td> <td> {{ form_errors(form.dateNaissance) }} <!-- {{ form_widget(form.dateNaissance) }} --> </td> <td> <input type="submit" value="Rechercher" class="bouton_submit_red" /> </td> </tr> </table> {{ form_rest(form) }} </form> <hr> <div id="resultats_recherche"> <table width="100%"> <thead> <tr> <th>Nom</th> <th>Prénom</th> <th>Date de Naissance</th> <th>Responsable</th> <th></th> </tr> </thead> {% for subarray in resultats %} <tr> <td>{{ subarray.nom }}</td> <td>{{ subarray.prenom }}</td> <td>{{ subarray.dateNaissance|date("d/m/Y") }}</td> <td>{{ subarray.NomResponsable }} {{ subarray.PrenomResponsable }}</td> <td style="text-align:right;"><a href="{{ path('LGBBourseLivresBundle_home_vente_fiche', { 'id': subarray.ideleve }) }}" ><input type="submit" class="bouton_submit_green_small" value="Visualiser la fiche"></a></td> </tr> {% endfor %} </table> </div> </div> <p style="text-align:left"><a href="#" ><input type="submit" class="bouton_submit_green_small" value="Ajouter un élève"></a></p> </div> {% endblock %} {% block aide %}Ici on recherche un élève soit par son ID. Soit en saisissant ses informations. Si l'élève n'est pas dans la liste cliquez sur "ajouter un élève".{% endblock %}
Partager