IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MVC PHP Discussion :

Récupérer et envoyer la valeur d'un input dans un lien [ZF 1.9]


Sujet :

MVC PHP

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut Récupérer et envoyer la valeur d'un input dans un lien
    Bonjour,

    J'essaie de faire une recherche, récupérer le mot rechercher et l'envoyer à travers un lien mais j'ai l'erreur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Exception information :
     
    Message: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
    Voilà comment je procède:

    Ma vue:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    echo' <div class="title_bloc">Recherche par agence :</div>
        <input type="text"  name="expression" value="" />';
        $search=$_GET['expression'];
        echo ' &nbsp;&nbsp;<a  href="'. $this->baseUrl() .'/referencement/rsannonceurs/search/' .$search . '">Envoyer</a>';
    Mon action:

    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
      function rsannonceursAction()
    	{
    		$this->view->layout()->setLayout('1column');
                    $this->view->headLink()->appendStylesheet(DEFAULT_SKIN_PATH . 'styles/recherches.css');
     
    		$tAgences = new Agences();
    		$field = "agence_rs";
     
                    $globalsearch = $this->_request->getParam('expression');
                    echo $globalsearch;
     
                    // J'envoie les parametres à la methode de la table
                    $this->view->search = $this->_request->getParam('search');
     
                    $this->view->data = $this->AlphabeticArrayMaker($tAgences->GetDataAgenceByRS($this->view->search),$field);
    	}
     
    	function AlphabeticArrayMaker($datas,$field)
    	{
    		//variable permettant de stocker la premiere lettre de la colonne "nomColonne"
     
    		$alphabet = array ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
     
    		foreach($datas as $row)
    		{
    			$lettre_tester = strtoupper(substr($row[$field], 0, 1));
     
    			$array[$lettre_tester][] = $row;
    		}
     
    		return $array;
    	}
    et enfin mon modèle:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     /*** Récupère l'agence suivi sa raison social ***/
            public function GetDataAgenceByRS($rs) {
    		$select = $this->getAdapter()->select();
    		$select->from($this->_name,'*');
    		$select->where('agence_rs = ?',$rs);
    		return $this->getAdapter()->fetchRow($select);
    	}
    C'est mon $_GET qui déconne ça va pas du tout! Mais comment récupérer sa valeur et l'envoyé sans passer par un formulaire?
    En gros pour un tout petit champs de recherche est ce que je suis obligée de passer par une Zend_Form?

    Merci d'avance pour votre aide.

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    Merci pour le lien...
    J'ai compris le mécanisme...maintenant n'y a-t-il pas d'autre moyen d'en arrivé a mon résultat sans passé par un formulaire?
    Si non, est ce que la method post permet de renvoyer les infos sur la même page?
    En gros est ce que je peux avoir:
    un fichier agence.phtml avec une <form action="agence.phtml method" method="post"> ?

    Dois-je passé par Zend_Form?

  3. #3
    Membre éclairé Avatar de manuscle
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Septembre 2004
    Messages : 488
    Points : 663
    Points
    663
    Par défaut
    Oui tu peux utiliser Zend_Form mais bon pour le moment vaut mieux essayer avec le plus simple...

    Dans ton cas j'utiliserais GET plutot que POST et essaie de garder le même nom de variable c'est plus 'lisible' ex:

    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
     
    // Dans ta vue
    <form method="get" action="<?php echo $this->baseUrl() .'/referencement/rsannonceurs' ?>">
     
    <label for="search">Recherche</label><input type="text" name="search" id="search" value="<?php echo $this->search ?>" />
     
    <input type="submit" value="ok" />
    </form>
     
    // Dans ton controlleur
    $this->view->search = $this->_request->getParam('search');
    $this->view->data = $this->AlphabeticArrayMaker($tAgences->GetDataAgenceByRS($this->view->search),$field);
     
    // Dans ton modele
            public function GetDataAgenceByRS($search = null) {
     
                    // Un terme a été saisi
                    if ($search) {
                $search = array('agence_rs LIKE ?' => $search);
                    }
            // On renvoi les résultats si terme ou tout si rien de saisi                        
            return $this->fetchAll($search);
        }

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    Pareil que mon dernier poste ça me renvoit la page d'accueil!

    J'arrive bien a récupérer la valeur saisie par contre pour la fonction getDataAgenceByRS($search) j'execute pas ma requête?? Je comprends pas bien ton array là...tu le rajoutes a quoi?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    public function getDataAgenceByRS($search) {
    		$select = $this->getAdapter()->select();
    		$select->from($this->_name,'*');
    		$select->where('agence_rs = ?',$search);
    		return $this->getAdapter()->fetchRow($select);
     
                     // Un terme a été saisi
                   /* if ($search) {
                        $search = array('agence_rs LIKE ?' => $search);
                    }
                    echo $search;
                    // On renvoi les résultats si terme ou tout si rien de saisi
                    return $this->fetchAll($search);*/
    	}

  5. #5
    Membre éclairé Avatar de manuscle
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Septembre 2004
    Messages : 488
    Points : 663
    Points
    663
    Par défaut
    La methode fetchAll() de ta classe de table reviens à faire SELECT * FROM taTable.
    Cette methode prend en premier parametre des arguments de recherche, donc

    $search = array('agence_rs LIKE ?' => $search) ajoute une clause where à ta requete
    ce qui te donne SELECT * FROM taTable WHERE agence_rs LIKE 'tonExpression';

    Regarde comment fonctionne les classes de table dans le bouquin de Julien Pauli, je crois que c'est celui-là que tu as....

    La methode te renvoi un objet en resultat, cet objet est un rowSet mais si tu veux obtenir les resultat sous forme de tableau tu n'a juste qu'à faire:
    return $this->fetchAll($search)->toArray();

    De plus je ne sais pas ce que tu veux obtenir, un seul résultat ou plusieur?
    Car tu dois savoir ceci:
    la methode fetchRow() te retourne qu'une seule ligne de resultat alors que la methode fetchAll() te renvoi TOUT les resultats.

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    Merci pour l'info. Je veux qu'il me retourne tous les résultats qui commencent par le mot saisi.


    Je reprends, j'ai l'impression de m'embrouiller en plus j'arrive pas à voir ou ça passe pas.

    Ma vue:

    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
    <div style="background: #fff; width: 100%; padding: 0 1em 1em; margin: -1em;"><br>
        <div class="title_bloc" width="50%">Recherche par ordre alpab&eacute;tique :</div><br>
    <?php
    $alphabet = array ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
    echo '<div style="width:25%; text-align:center;"><table><tr><td class="table-ligne1-centre" valign="top">';
    foreach ($alphabet as $letter) {
     
        if ($letter == $this->letter) {
        echo $letter;
     
        } else {
     
            echo '&nbsp;<a href="'. $this->baseUrl() .'/referencement/annonceurs/lettre/' .$letter . '">' . $letter . '</a>&nbsp;';
        }
     
    }
    echo '</td></tr></table></div><br>';
     
     
    ?>
    <form method="get" action="<?php echo $this->baseUrl() .'/referencement/rsannonceurs' ?>">
     
    <label for="search">Recherche : </label><input type="text" name="search" id="search" value="<?php echo $this->search ?>" />
     
    <input type="submit" value="ok" />
    </form>
     
    <?php
     
    if ($this->data===null){
       echo '<h1 style="margin: 1em -12px 10px">Aucun r&eacute;sultat n\'a &eacute;t&eacute; retourn&eacute;</h1>';
     
    }
    else{
    foreach($this->data as $letter =>  $rows){
    	echo '<h1 style="margin: 1em -12px 10px">' . $letter . '</h1>';
            print '<div style="width:100%; text-align:center;">
            <table width="100%"  cellspacing="2" cellpadding="2">';
     
            $i=0;
    	foreach($rows as $row){
     
                      if(!($i%2)){
                          print '</tr>';
                          print '<td><a href="' . $this->baseUrl() . '/index/recherche?cr=poste&ag=' . $row['agence_id'] . '/'.$row['agence_rs'].'">' . $row['agence_rs'] . '</a></td> ';
     
                           $i++;
                    }else {
                             print '<td><a href="' . $this->baseUrl() . '/index/recherche?cr=poste&ag=' . $row['agence_id'] . '/'.$row['agence_rs'].'">' . $row['agence_rs'] . '</a></td></tr> ';
                            $i++;
     
                      }
             }         
    }
    print '</tr></table></div>';
    }
    ?>
    </div>
    Mon contrôleur:

    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
    function rsannonceursAction()
    	{
    		$this->view->layout()->setLayout('1column');
                    $this->view->headLink()->appendStylesheet(DEFAULT_SKIN_PATH . 'styles/recherches.css');
     
    		$field = "agence_rs";
                    // J'envoie les parametres à la methode de la table
                    $this->view->search = $this->_request->getParam('search');
                    $this->view->data = $this->AlphabeticArrayMaker($tAgences->getDataAgenceByRS($this->view->search),$field);
     
    }
     
    function AlphabeticArrayMaker($datas,$field)
    	{
    		//variable permettant de stocker la premiere lettre de la colonne "nomColonne"
     
    		$alphabet = array ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
     
    		foreach($datas as $row)
    		{
    			$lettre_tester = strtoupper(substr($row[$field], 0, 1));
     
    			$array[$lettre_tester][] = $row;
    		}
                    //print_r($array);
    		return $array;
    	}
    et enfin mon modèle:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     public function getDataAgenceByRS($search = NULL) {
     
                     // Un terme a été saisi
                    if ($search) {
                        $search = array('agence_rs LIKE ?' => $search);
                    }
                     print_r($search);
                    // On renvoi les résultats si terme ou tout si rien de saisi
                    return $this->fetchAll($search);
                    //return $this->fetchAll($search)->toArray();
    	}
    J'obtiens une page blanche qui table sur "rsannonceurs?search=activrh" .
    Mon "print_r($search);" ne m'affiche rien.

  7. #7
    Membre éclairé Avatar de manuscle
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Septembre 2004
    Messages : 488
    Points : 663
    Points
    663
    Par défaut
    Et que te renvoi $this->_request->getParam('search'); ?

  8. #8
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    ça me renvoit bien le mot saisi c'est après que ça passe plus...

  9. #9
    Membre éclairé Avatar de manuscle
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Septembre 2004
    Messages : 488
    Points : 663
    Points
    663
    Par défaut
    c'est quand même bizare ça, si tu fait ceci qu'obtiens-tu?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
     public function getDataAgenceByRS($search = NULL) {
                    print_r($search);
     
                     // Un terme a été saisi
                    if ($search) {
                        $search = array('agence_rs LIKE ?' => $search);
                    }
     
                    // On renvoi les résultats si terme ou tout si rien de saisi
                    return $this->fetchAll($search);
                    //return $this->fetchAll($search)->toArray();
    	}

  10. #10
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    toujours rien...j'ai que le mot saisi qui s'affiche

  11. #11
    Membre éclairé Avatar de manuscle
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Septembre 2004
    Messages : 488
    Points : 663
    Points
    663
    Par défaut
    Peux-tu me donner le contenu entier de ta classe de table?

  12. #12
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    Ca va être un peu long! désolée
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    <?php
    class Agences extends Pi_Db_Model
    {	
        protected $_name = 'agences'; // S�lectionne la table
     
        protected $_primary = 'agence_id'; // d�finie la cl� primaire
     
    	/*
    	Fonction qui compte le nombre d'agence
    	*/
    	public function getNbAgences() {
    		$select = $this->getAdapter()->select();
    		$select->from('agences','count(agence_id) as total');
    		return $this->getAdapter()->fetchRow($select);
    	}
     
    	public function GetDataAgenceById($id) {
    		$select = $this->getAdapter()->select();
    		$select->from($this->_name,'*');
    		$select->where('agence_id = ?',$id);
    		return $this->getAdapter()->fetchRow($select);
    	}
     
    	public function GetNextCodeSite($id) {
    		$select = $this->getAdapter()->select();
     
    		$select->from($this->_name,'MAX(`agence_site`) as uppercodesite');
    		$select->where('cli_id = ?',$id);
    		// echo $select->__toString();
     
    		$result = $this->getAdapter()->fetchRow($select);
    		return ($result['uppercodesite'] != 0) ? (int)($result['uppercodesite'] + 1) : 1 ;
    	}
     
    	public function getAgenceByCodeSite($cli_id,$code_site) {
     
    		$select = $this->getAdapter()->select();
    		$select->from('agences','*');
    		$select->where('cli_id = ?',$cli_id);
    		$select->where('agence_site = ?',$code_site);
     
    		return (int) $this->getAdapter()->fetchRow($select);
    	}
     
    	public function getAllAgences($cli_id = null, $cols = '*') {
        if ($cols != '*') $cols = explode(' ',$cols);
    		$select = $this->getAdapter()->select();
    		$select->from(array('ag' => 'agences'),$cols);
    		if($cli_id != null)
    		{
    			$select->where('cli_id = ?',$cli_id);
    		}
    		return $this->getAdapter()->fetchAll($select);
    	}
     
    	public function getAllAgencesForSeo() 
    	{
    		$select = $this->getAdapter()->select();
    		$select->from(array('ag' => 'agences'),array('agence_id','agence_rs'));
    		$select->order('agence_rs ASC');
    		return $this->getAdapter()->fetchAll($select);
    	}
     
            public function getAllAgencesByAlpha($letter)
    	{
                $alphabet = array ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
     
                $select = "SELECT * FROM `pagesinterim`.`agences`";
     
                // echo $letter;
                 echo "<br/>";
                if ($letter && in_array($letter, $alphabet)) {
     
                    $select .= " WHERE agence_rs LIKE '$letter%' ORDER BY agence_rs ASC";
                  //  echo $select;
                    $agence_alpha = Zend_Registry::get('db')->query($select)->fetchAll();
                  //  print_r($agence_alpha);
                    return $agence_alpha;
     
                }
     
            }
            /*** Récupère l'agence suivant sa raison social ***/
     
            public function getDataAgenceByRS($search = NULL) {
                    print_r($search);
     
                     // Un terme a été saisi
                    if ($search) {
                        $search = array('agence_rs LIKE ?' => $search);
                    }
     
                    // On renvoi les résultats si terme ou tout si rien de saisi
                    return $this->fetchAll($search);
                    //return $this->fetchAll($search)->toArray();
    	}
     
     
    	/*
    	 * Function getOptions : retourne un tableau contenant les informations utiliser lors de la cr�ation des options d'un select.
    	 */
    	public function getOptions($cli_id = null,$ag_id=null) {
    		$select = $this->getAdapter()->select();
    		$select->from($this->_name,array('agence_id','agence_rs','agence_ville'));
    		if ($cli_id) $select->where('cli_id = ?',$cli_id);
        if ($ag_id) $select->where('agence_id = ?',$ag_id);
        // echo $select->__toString();
    		$arryAll = $this->getAdapter()->fetchAll($select);
     
    		$arryData = array();
    		foreach($arryAll as $data) {
    			$arryData[$data['agence_id']] = $data['agence_rs'] . ' (' . $data['agence_ville'] . ')';
    		}
     
    		if(count($arryData) > 1){
    			$arryData = array(''=>'Selectionnez') + $arryData;
    		}
     
    		return $arryData;
    	}
     
     
    	public function getAgences($criteria = null, $paginate = null, $sort = null, $toString = False) 
    	{		
    		$select = $this->getAdapter()->select();
     
    		$select->from(array('Ag' => 'agences'),'*');
     
    		// Jointure sur la r�gion
    		$select->joinLeft(array('cli' => 'clients'),
    			'(Ag.cli_id = cli.cli_id)',
    			'*'
    		);
     
    		// Jointure sur le pays
    		$select->joinLeft(array('pa' => 'pays'),
    			'(Ag.agence_pays = pa.pays_iso_number)',
    			'*'
    		);
     
     
     
    		/* 
    		 * Sort : D�finie l'ordre d'affichage du r�sulat
    		 * Direction et champ
    		 */
    		switch($sort) {
    			case 'nom':
    				$order['dir'] = 'ASC';
    				$order['sort'] = 'agence_rs';
    				break;
    			case 'cp':
    				$order['dir'] = 'ASC';
    				$order['sort'] = 'agence_cp';
    				break;
    			case 'ville':
    				$order['dir'] = 'ASC';
    				$order['sort'] = 'agence_ville';
    				break;
    			default:
    				$order['dir'] = 'ASC';
    				$order['sort'] = 'agence_rs';
    				break;
    		}
     
    		// @param : Mots cl�s
    		if(!empty($criteria['keys'])) {
    			$params_where['keys'] = explode(",", strtr($criteria['keys'],' ',','));
     
    			$strWhere = "agence_rs LIKE '%".trim($params_where['keys'][0])."%'";
    			for($i=1;$i<sizeof($params_where['keys']);$i++) {
    				$strWhere .= " OR agence_rs LIKE '%" . trim($params_where['keys'][$i]) . "%'";
    			}
    			$select->where($strWhere);
    		}
     
    		//******** Localisation
     
    		//*** Crit�re pays
    		// @ param - string
    		if(!empty($criteria['pays']) && $criteria['pays'] != '999') {
    			$select->where('agence_pays = ?', (int) $criteria['pays']);
    		}
     
    		//*** Crit�re R�gion/D�partement
    		// @ param - string
    		if(!empty($criteria['zid'])) {
     
    			// Si > 100 : recherche d'une region
    			if($criteria['zid'] > 100) {
    				// Recherche dans chaque d�partement de la r�gion
    				$tDepartements = new Departements();
    				$dpts_selected = $tDepartements->getAllDptByRegionId(($criteria['zid'] - 100));
     
    				// Zend_Debug::Dump($dpts_selected,'Request Select');
     
    				// Boucle sur les d�partements trouv�s
    				$strWhere = "agence_region LIKE '" . $dpts_selected[0]["dpt_id"] . "'";
    				for($i=1;$i<sizeof($dpts_selected);$i++) {
    					$strWhere .= " OR agence_region = '" . $dpts_selected[$i]["dpt_id"] . "'";
    				}
    				$select->where($strWhere);
    			}
     
    			// Si  1 <= x  <= 100 recherche d'un d�partement
    			if($criteria['zid'] >= 1 && $criteria['zid'] <= 100 ) {
    				$select->where('agence_region = ?', (int) $criteria['zid']);
    			}
    		}
     
    		// @param : Location
    		// string / int
    		//*** Localisation 
    		// Tableau de ville
    		if(!empty($criteria['agencesInsideCircle'])){
    			$where_commune = "Ag.`agence_id` IN (";
    			foreach($criteria['agencesInsideCircle'] as $agence){
    				$where_commune .= "'" . $agence['agence_id'] ."',";
    			}
    			$where_commune = rtrim($where_commune,',').")";
    			$select->where($where_commune);
    		} else if(!empty($criteria['location'])) {
    			$location = $criteria['location'];
     
    			// Recherche par code postal sur 4,5 chiffres
    			if(preg_match('`^[0-9]{4,5}$`',$location)) {
    				$where_location = "agence_cp LIKE '%" . (int)$location . "%'";
    			}else if(preg_match('`^[0-9]{2}$`',$location)) { // recherche dans tout les codes postaux commen�ant par XX et les r�gions
    				$where_location = "agence_cp LIKE '%" . (int)$location . "%'";
    			} else {
    				$where_location = $this->getAdapter()->quoteInto("agence_ville LIKE ?", '%'.$location.'%');
    				$where_location .= ' OR ' . $this->getAdapter()->quoteInto("agence_ville LIKE ?", '%'.$location.'%');
    				$where_location .= ' OR ' . $this->getAdapter()->quoteInto("agence_ville LIKE ?", '%'.$location.'%');
    			}
    			$select->where($where_location);
    		}
     
    		//*** Pagination
    		if(!empty($paginate)) {
    			// Affecte une limite  � l'affichage et calcul automatiquement l'offset en fonction de la page et du nombre d'�l�ment par page
    			$select->limitPage($paginate['currentPage'], $paginate['rowPerPage']); 
    		}
     
    		//*** Sort et direction
        $select->order('cli_logo DESC');
    		$select->order($order['sort'] . " " . $order['dir']);
     
    		//Zend_Debug::Dump($select->__toString(),'Request Select');
     
    		//*** Effectue la requ�te et renvoie les r�sultats
    		if($toString == True) {
    			return $select;
    		}
     
    		return $this->getAdapter()->fetchAll($select);
    	}
     
    	/*
    	R�cup�re toutes les villes dans un carr� en fonction du poitn d'origine et du rayon
    	*/
    	public function getAgencesByLatLngSquare($centre_latitude,$centre_longitude,$rayon) {
    		// Correspondance approximative de kilometre vers degr� longitude
    		$distance_degre_lat = ($rayon / 1.609344) / (69.1);
    		$distance_degre_long = ($rayon / 1.609344) / (53);
     
    		// On s�lectionne grossi�rement un carr� pour la s�lection des villes
    		$point_nord_est_lat 	= $centre_latitude + $distance_degre_lat; 
    		$point_nord_est_long 	= $centre_longitude + $distance_degre_long;
     
    		$point_sud_ouest_lat 	= $centre_latitude - $distance_degre_lat;
    		$point_sud_ouest_long 	= $centre_longitude - $distance_degre_long;
     
     
    		$select = $this->getAdapter()->select();
    		$select->from(array('Ag' => $this->_name),array('agence_id','agence_lat','agence_long'));
    		$select->where('agence_lat >=?',$point_sud_ouest_lat);
    		$select->where('agence_long >=?',$point_sud_ouest_long);
    		$select->where('agence_lat <= ?',$point_nord_est_lat);
    		$select->where('agence_long <=?',$point_nord_est_long);
     
    		return $this->getAdapter()->fetchAll($select);
    	}
     
      public function getById($id) {
        return $this->getDataAgenceById($id);
      }
    }

  13. #13
    Membre éclairé Avatar de manuscle
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Septembre 2004
    Messages : 488
    Points : 663
    Points
    663
    Par défaut
    Tu recherche bien un terme sue tu es sûre de trouver au moins?

    J'ai zappé mais normalement tu dois mettre les pourcentages car sinon il recherche l'expression exacte...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
     public function getDataAgenceByRS($search = NULL) {
                    print_r($search);
     
                     // Un terme a été saisi
                    if ($search) {
                        $search = array('agence_rs LIKE ?' => "%{$search}%");
                    }
     
                    // On renvoi les résultats si terme ou tout si rien de saisi
                    return $this->fetchAll($search);
                    //return $this->fetchAll($search)->toArray();
    	}
    Si tu n'a pas de résultat essaie de faire ta requete comme dans ta methode getAllAgencesByAlpha

  14. #14
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    oui oui je cherche bien un résultat qui existe...l

    par contre même en modifiant la fonction:
    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
       public function getDataAgenceByRS($search) {
                    print_r($search);
     
                     $select = "SELECT * FROM `pagesinterim`.`agences`";
                     echo $select;
     
                     if ($search) {
                          $select .= " WHERE agence_rs LIKE '%$search%' ORDER BY agence_rs ASC";
                          echo $select;
                          $agence_alpha = Zend_Registry::get('db')->query($select)->fetchAll();
                          print_r($agence_alpha);
                          return $agence_alpha;
                     }
     
    	}
    Non le truc c'est que j'ai l'impression qu'il y va pas dans cette fonction vu qu'il ne m'affiche pas la valeur du $search.

    Je comprends plus rien là.

    Apparemment c'est mon objet agence qui pose pb!

    Si je lui met, un objet non instancié il me ressort le même résultat!

    et si j'en instancie un nouveau, il me renvoi la page d'accueil :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     $rsAgences = new Agences();
     $this->view->data = $this->AlphabeticArrayMaker($rsAgences->getDataAgenceByRS($this->view->search),$field);

  15. #15
    Membre éclairé Avatar de manuscle
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Septembre 2004
    Messages : 488
    Points : 663
    Points
    663
    Par défaut
    t'a bien toute les erreurs php qui s'affichent?
    error_reporting(E_ALL|E_STRICT); // Au debut de public/index.php

    car là je bloque aussi...
    Je vois que dans ton controlleur tu appele la methode GetDataAgenceByRS et que dans ton modele la methode s'appelle getDataAgenceByRS... T'a vérifié la casse?

    De toute façon si c'est une methode qui n'existe pas ça devrait te l'afficher...... tout dépend comment php est réglé pour t'afficher les erreurs.

  16. #16
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    oui oui j'ai vérifié la casse c bon...regarde mon dernier post...c'est l'objet Agences qui pose problème...mais je saisi toujours pas??

  17. #17
    Membre éclairé Avatar de manuscle
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Septembre 2004
    Messages : 488
    Points : 663
    Points
    663
    Par défaut
    Bon on va reprendre par etape...
    Déjà tu me dit que tu attrape bien le parametre 'search' dans ton controlleur
    Donc déjà fait ta requete depuis le controlleur direct
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    public function rsannonceursAction() {
     
                     $select = "SELECT * FROM `pagesinterim`.`agences`";
                     echo $select;
                   $this->view->search = $this->_request->getParam('search');
                     if ($this->view->search) {
                          $select .= " WHERE agence_rs LIKE '%{$this->view->search}%' ORDER BY agence_rs ASC";
    }
                          echo $select;
                          $agence_alpha = Zend_Registry::get('db')->query($select)->fetchAll();
    Zend_Debug::dump($agence_alpha, 'resultats pour:' . $this->view->search);
    exit;
    }
    Si ça marche, essaie avec la methode sans passer par ArrayMakerTruc
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    public function rsannonceursAction() {
     
                    $this->view->search = $this->_request->getParam('search');
    $rsAgences = new Agences();
     $agence_alpha = $rsAgences->getDataAgenceByRS($this->view->search);
    Zend_Debug::dump($agence_alpha, 'resultats pour:' . $this->view->search);
    exit;
    }
    Si dans le deuxieme test tu as un resultat c'est que ça vient pas de la classe de table

  18. #18
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    oui effectivement les tests fonctionnent.
    Ça doit venir de ma classe de table.
    Mais je vois pas ou et je comprends pourquoi alors ma recherche par ordre alphabétique fonctionne??

  19. #19
    Membre éclairé Avatar de manuscle
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Septembre 2004
    Messages : 488
    Points : 663
    Points
    663
    Par défaut
    Ben non!

    Si le deuxième test fonctionne, c'est que ça vient pas de ta classe de table vu que la methode te renvoie un résultat !

    Le constructeur de ta classe se trouve dans la classe abstraite Zend_Db_Table_Abstract
    Toute les classes de tables étendent Zend_Db_Table_Abstract, en l'occurence, ta classe Agences étend d'abord Pi_Db_Model qui doit surement etendre Zend_Db_Table_Abstract.

  20. #20
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    488
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 488
    Points : 134
    Points
    134
    Par défaut
    mais oui je suis bête!
    mais c ou que ça coince alors vu la fonction AlphabeticArrayMaker semble me retourner le bon tableau.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $this->view->data = $this->AlphabeticArrayMaker($agence_alpha,$field);
    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
    function AlphabeticArrayMaker($datas,$field)
    	{
    		//variable permettant de stocker la premiere lettre de la colonne "nomColonne"
     
    		$alphabet = array ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
     
                    print_r($datas);
     
                        echo '<br><br>';
    		foreach($datas as $row)
    		{
    			$lettre_tester = strtoupper(substr($row[$field], 0, 1));
     
    			$array[$lettre_tester][] = $row;
    		}
     
                    print_r($array);
    		return $array;
    	}
    C'est mon affichage qui plante ou c'est ma form qui pose pb?:

    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
    <div style="background: #fff; width: 100%; padding: 0 1em 1em; margin: -1em;"><br>
        <div class="title_bloc" width="50%">Recherche par ordre alpab&eacute;tique :</div><br>
    <?php
    $alphabet = array ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
    echo '<div style="width:25%; text-align:center;"><table><tr><td class="table-ligne1-centre" valign="top">';
    foreach ($alphabet as $letter) {
     
        if ($letter == $this->letter) {
        echo $letter;
     
        } else {
     
            echo '&nbsp;<a href="'. $this->baseUrl() .'/referencement/annonceurs/lettre/' .$letter . '">' . $letter . '</a>&nbsp;';
        }
     
    }
    echo '</td></tr></table></div><br>';
     
    ?>
    <form method="get" action="<?php echo $this->baseUrl() .'/referencement/rsannonceurs' ?>">
     
    <label for="search">Recherche : </label><input type="text" name="search" id="search" value="<?php echo $this->search ?>" />
     
    <input type="submit" value="ok" />
    </form>
     
    <?php
     
    if ($this->data==null){
       echo '<h1 style="margin: 1em -12px 10px">Aucun r&eacute;sultat n\'a &eacute;t&eacute; retourn&eacute;</h1>';
    }
    else{
    foreach($this->data as $letter =>  $rows){
    	echo '<h1 style="margin: 1em -12px 10px">' . $letter . '</h1>';
            print '<div style="width:100%; text-align:center;">
            <table width="100%"  cellspacing="2" cellpadding="2">';
     
            $i=0;
    	foreach($rows as $row){
     
                      if(!($i%2)){
                          print '</tr>';
                          print '<td><a href="' . $this->baseUrl() . '/index/recherche?cr=poste&ag=' . $row['agence_id'] . '/'.$row['agence_rs'].'">' . $row['agence_rs'] . '</a></td> ';
                          /** 23/02/2009: La ligne précédente remplace la ligne suivante: on utilise directiment agence_id pour afficher les annonces d'une agence, sans faire une nouvelle recherche présentant les différentes agences qui auraient un nom proche (SM) */
                        // 		echo '~ <a href="' . $this->baseUrl() . '/annonceur/' . $this->urlize($row['agence_rs']) . '">' . $row['agence_rs'] . '</a> ';
                           $i++;
                    }else {
                             print '<td><a href="' . $this->baseUrl() . '/index/recherche?cr=poste&ag=' . $row['agence_id'] . '/'.$row['agence_rs'].'">' . $row['agence_rs'] . '</a></td></tr> ';
                            $i++;
     
                      }
             }       
    }
    print '</tr></table></div>';
    }
    ?>
    </div>
    Je suis larguée là!

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Récupérer la valeur d'un input dans une jsp
    Par clavben dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 07/02/2012, 12h59
  2. Réponses: 11
    Dernier message: 23/04/2009, 14h43
  3. Récupérer valeur chekbox et input dans un DIV
    Par axanta dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 12/11/2008, 15h51
  4. Réponses: 9
    Dernier message: 29/08/2008, 14h35
  5. Utiliser la valeur d'un input dans une variable php
    Par megane dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 09/08/2005, 16h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo