Bonjour à tous,
J'ai actuellement, une recherche à l'aide d'un formulaire qui fonctionne très bien:
monModule/templates/indexSuccess.php:
Code php : 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 <form method="get" name="recherche_categories" action="<?php echo url_for('monModule/index');?>"> <fieldset> <legend>Recherche une pièce par catégorie</legend> <select name="marques"> <option value="Tous">Tous</option> <?php foreach ($ChoixMarques as $ChoixMarque): ?> <option value="<?php echo $ChoixMarque->getId()?>"><?php echo $ChoixMarque->getConstructeur() ?></option> <?php endforeach; ?> </select> <select name="gammes"> <option value="Tous">Tous</option> <?php foreach ($ChoixGammes as $ChoixGamme): ?> <option value="<?php echo $ChoixGamme->getId()?>"><?php echo $ChoixGamme->getIntitule() ?></option> <?php endforeach; ?> </select> <select name="categories"> <option value="Tous">Tous</option> <?php foreach ($ChoixCategories as $ChoixCategorie): ?> <option value="<?php echo $ChoixCategorie->getIndexCategorie()?>"><?php echo $ChoixCategorie->getFamille() ?></option> <?php endforeach; ?> </select> </fieldset> <input type="submit" name="submit" value="Rechercher" /> </form> <?php if (isset($submit)) { if ($marque == 'Tous' && $gamme == 'Tous' && $categorie == 'Tous') { echo 'Veuillez affiner votre recherche'; } else { ?> <h1>List</h1> /.. ../ <br /><br /> <?php } } ?> <hr /> <a href="<?php echo url_for('monModule/new') ?>">New</a>
monModule/actions/actions.classe.php:
Code php : 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 public function executeIndex(sfWebRequest $request) { $this->ChoixMarques = Doctrine::getTable('Marque') ->createQuery('a') ->orderBy('constructeur') ->execute(); $this->ChoixGammes = Doctrine::getTable('Gammes') ->createQuery('b') ->orderBy('Intitule') ->execute(); $this->ChoixCategories = Doctrine::getTable('Categorie') ->createQuery('c') ->select() ->where('c.id_parent = 269') ->orderBy('c.famille') ->execute(); if($request->getParameter('marques')) { $marque = $request->getParameter('marques'); $categorie = $request->getParameter('categories'); $gamme = $request->getParameter('gammes'); $submit = $request->getParameter('submit'); if($request->getParameter('marques')=='Tous' && $request->getParameter('gammes')=='Tous' && $request->getParameter('categories')=='Tous') { } else { if ($marque == 'Tous') { $requete_marque = 'd.index_marque LIKE "%"'; } else { $requete_marque = 'd.index_marque = '.$request->getParameter('marques'); } if ($categorie == 'Tous') { $requete_categorie = 'd.index_famille LIKE "%"'; } else { $requete_categorie = 'd.index_famille = '.$request->getParameter('categories'); } if ($gamme == 'Tous') { $requete_gamme = 'd.index_gamme LIKE "%"'; } else { $requete_gamme = 'd.index_gamme = '.$request->getParameter('gammes'); } $this->catalogue_requete = Doctrine::getTable('Catalogue') ->createQuery('d') ->select() ->leftJoin('d.JointuresGammes e') ->where($requete_marque) ->andWhere($requete_categorie) ->andWhere($requete_gamme) ->execute(); } } }
Cependant, pour des raison évidentes, étant donné qque je vais avoir des milliers d'entrées, je souhaite faire une pagination.
J'ai donc rajouter au template:
Code php : 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 <h1>List</h1> /.. ../ <div style="width:20px;float:left;margin-top:3px;margin-right:10px"> <?php echo link_to('first', 'monModule/index?marques='.$marque.'&gammes='.$gamme.'&categories='.$categorie.'&submit=Rechercher&page='.$pager->getFirstPage()) ?> </div> <div> <?php if ($pager->haveToPaginate()) { ?> <?php $links = $pager->getLinks(); foreach ($links as $page): ?> <div style="padding:5px 5px 5px 5px;border:#000000 thin solid;float:left;width:10px;margin-left:3px;font-size:10px" > <?php echo ($page == $pager->getPage()) ? $page : link_to($page, 'monModule/index?marques='.$marque.'&gammes='.$gamme.'&categories='.$categorie.'&submit=Rechercher&page='.$page) ?> </div> <?php endforeach ?> <?php } ?> </div> <div style="width:20px;float:left;margin-left:10px;margin-top:3px;"> <?php echo link_to('last', 'monModule/index?marques='.$marque.'&gammes='.$gamme.'&categories='.$categorie.'&submit=Rechercher&page='.$pager->getLastPage()) ?> </div> <br /><br /> <?php } } ?> <hr /> <a href="<?php echo url_for('monModule/new') ?>">New</a>
je bloque pour le fichier actions.class pour que la pagination s'effectue bien sur ma requete. J'ai essayé ceci mais la pagination se fait sans mes where:
Code php : 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 ../ $catalogue_requete = Doctrine::getTable('Catalogue') ->createQuery('d') ->select() ->leftJoin('d.JointuresGammes e') ->where($requete_marque) ->andWhere($requete_categorie) ->andWhere($requete_gamme); $this->pager = new sfDoctrinePager('Catalogue', 10); $this->pager->getQuery($catalogue_requete); $this->pager->setPage($this->getRequestParameter('page',1)); $this->pager->init(); } } }
Merci de votre aide...
Partager