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

Zend Framework PHP Discussion :

appel de fonction dans Ajaxcontroller [ZF 1.10]


Sujet :

Zend Framework PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    380
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 380
    Par défaut appel de fonction dans Ajaxcontroller
    Bonjour à tous,
    alors voila, mon problème est simple :
    j'ai ce AjaxController :
    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
     
    class AjaxController extends Zend_Controller_Action 
    {
    	public function clientAction() 
    	{
             if($this->_request->isXmlHttpRequest())
    	{
                $this->_helper->layout->disableLayout();
                $this->_helper->viewRenderer->setNoRender(true);
            }
     
    	$TClients = new TClients;
     
    	$Clients = $TClients->selectData();
     
    	foreach ($Clients as $Client) 
    	{
    	$list[] = array(  'id'=> $Client->numero_client, 'text'=> $Client->nom_client);
    	}
     
    	$this->_helper->json($list, array('enableJsonExprFinder' => true));
        }
    	public function monclientAction() 
    	{
                if($this->_request->isXmlHttpRequest())
                {
    	        $this->_helper->layout->disableLayout();
                }
     
    		$array = $this->_request->getParam('id');
    		$numero_client = $array[0];
     
    		$TClients = new TClients;
     
    		$Clients = $TClients->selectDataByID($numero_client);
     
    		$html = ' 
    		<table>
    			<tr>
    				<th>Num&eacute;ro</th>
    				<th>Nom</th>
    				<th>Raison sociale</th>
    				<th>Responsable</th>
    				<th>Adresse</th>
    				<th>Code postal</th>
    				<th>Ville</th>
    				<th>Département</th>
    				<th>Pays</th>
    				<th>Mail</th>
    				<th>Telephone Domicile</th>
    				<th>Action</th>
    			</tr>
    		';	
     
    	foreach($Clients as $client) {
    		$html .= '<tr>';
    		$html .= '<td>'.$client->numero_client.'</td>';
    		$html .= '<td>'.$client->nom_client.'</td>';
    		$html .= '<td>'.$client->numero_raison_sociale_client.'</td>';
    		$html .= '<td>'.$client->responsable_client.'</td>';
    		$html .= '<td>'.$client->adresse_client.'</td>';
    		$html .= '<td>'.$client->code_postal_client.'</td>';
    		$html .= '<td>'.$client->ville_client.'</td>';
    		$html .= '<td>'.$client->numero_departement_client.'</td>';
    		$html .= '<td>'.$client->numero_pays_client.'</td>';
    		$html .= '<td>'.$client->mail_client.'</td>';
    		$html .= '<td>'.$client->telephone_domicile_client.'</td>';					
    		$html .= '<td>';
    		$html .= '<a href="'.$this->view->url(array('controller'=>'index'
    													  ,'action'=>'modifier'
    													  , 'id'=>$client->numero_client))
    													  .'">Modifier</a>&nbsp;&nbsp;';
    		$html .= '<a href="'.$this->view->url(array('controller'=>'index'
    		 												,'action'=>'supprimer'
    		 												, 'id'=>$client->numero_client))
    		 												.'">Supprimer</a>&nbsp;&nbsp;';
            $html .= '<a href="'.$this->view->url(array('controller'=>'index'
            												,'action'=>'consulter'
            												, 'id'=>$client->numero_client))
            												.'">Consulter</a>';
    		$html .= '</td>';
    		$html .= '</tr>';
    	}
     
    		$html .= '</table>';
     
    		$this->view->html = $html;
     
    	}	
     
    	public function villeclientAction() 
    	{
    	    if($this->_request->isXmlHttpRequest())
    	   {
    	       $this->_helper->layout->disableLayout();
                   $this->_helper->viewRenderer->setNoRender(true);
               }
     
    		$TClients = new TClients;
    		$Clients = $TClients->selectData();
     		foreach ($Clients as $Client) 
    		{
    			$list[] = array(  'id'=> $Client->ville_client, 'text'=> $Client->ville_client);
    		}
     
           $this->_helper->json($list, array('enableJsonExprFinder' => true));
           }
     
    	public function mavilleclientAction() 
    	{
     	    if($this->_request->isXmlHttpRequest())
    	    {
    	       $this->_helper->layout->disableLayout();
                 }
     
    		$array = $this->_request->getParam('id');
    		$ville_client = $array[6]; 	
     
    		$TClients = new TClients;
     
    		$VilleClients = $TClients->selectDataByVille($ville_client);
     
    		$html = ' 
    		<table>
    			<tr>
    				<th>Num&eacute;ro</th>
    				<th>Nom</th>
    				<th>Raison sociale</th>
    				<th>Responsable</th>
    				<th>Adresse</th>
    				<th>Code postal</th>
    				<th>Ville</th>
    				<th>Département</th>
    				<th>Pays</th>
    				<th>Mail</th>
    				<th>Telephone Domicile</th>
    				<th>Action</th>
    			</tr>
    		';	
     
    	foreach($VilleClients as $client) {
    		$html .= '<tr>';
    		$html .= '<td>'.$client->numero_client.'</td>';
    		$html .= '<td>'.$client->nom_client.'</td>';
    		$html .= '<td>'.$client->numero_raison_sociale_client.'</td>';
    		$html .= '<td>'.$client->responsable_client.'</td>';
    		$html .= '<td>'.$client->adresse_client.'</td>';
    		$html .= '<td>'.$client->code_postal_client.'</td>';
    		$html .= '<td>'.$client->ville_client.'</td>';
    		$html .= '<td>'.$client->numero_departement_client.'</td>';
    		$html .= '<td>'.$client->numero_pays_client.'</td>';
    		$html .= '<td>'.$client->mail_client.'</td>';
    		$html .= '<td>'.$client->telephone_domicile_client.'</td>';					
    		$html .= '<td>';
    		$html .= '<a href="'.$this->view->url(array('controller'=>'index'
    													  ,'action'=>'modifier'
    													  , 'id'=>$client->numero_client))
    													  .'">Modifier</a>&nbsp;&nbsp;';
    		$html .= '<a href="'.$this->view->url(array('controller'=>'index'
    		 												,'action'=>'supprimer'
    		 												, 'id'=>$client->numero_client))
    		 												.'">Supprimer</a>&nbsp;&nbsp;';
            $html .= '<a href="'.$this->view->url(array('controller'=>'index'
            												,'action'=>'consulter'
            												, 'id'=>$client->numero_client))
            												.'">Consulter</a>';
    		$html .= '</td>';
    		$html .= '</tr>';
    	}
     
    		$html .= '</table>';
     
    		// Assignation de mes différents éléments à ma vue
    		$this->view->html = $html;
     
    }
    et ma classe
    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
     
    <?php
    class TClients extends Zend_Db_Table_Abstract {
     
    	protected $_name = 'client';
            protected $_primary = "numero_client";
     
    	public function selectData () 
            {
    		$sql = "SELECT * FROM client";
    	        return $this->getAdapter('db')->fetchAll($sql);
    	}
     
    	public function selectDataByID ($numero_client) 
    	{
    		$sql = "SELECT * FROM client WHERE numero_client = ".$numero_client;
    		return $this->getAdapter('db')->fetchAll($sql);		
    	}
     
    	public function selectDataByVille($ville_client) 
    	{
    		$sql = "SELECT * FROM client WHERE ville_client = '".$ville_client." ' ";
     		return $this->getAdapter('db')->fetchAll($sql);		
    	}
     
    	public function select_all_client($id)
    	{
    		$db = Zend_Db_Table_Abstract::getDefaultAdapter(); 		 
    		$select = $db->select()
    		->from($this->_name)
    		->where('numero_client='.$id);
     
    		return  $db->fetchAll($select);
    	}
     
    }
    ?>
    J'utilise 2 sugestbox une pour recherche de nom, une pour recherche par ville.
    clientAction() et monclientAction() "alimentent la suggestbox de recherche par nom et villeclientAction() et mavilleclientAction() alimentent la suggestbox de recherche par ville.

    Actuellement, les villes me sont affichées de manière correcte mais le problème qui se pose est le suivant, ma suggestbox ville me propose autant de fois le même nom de ville qu'il y a de client habitant dans cette ville
    exemple :
    durand habitant paris
    lefranc habitant paris
    => ma suggestboxvilleclient me proposera paris et paris le premier correspondant à durand et le second à lefranc.

    Je souhaiterais qu'une seule ville s'affiche et que lorsque je clique dessus, il me propose une liste des clients habitants dans cette ville.

    J'espère avoir été clair ...

    concernant ma requête dans la fonction mavilleclientAction, elle est parfaitement opérationnelle et renvoi parfaitement ce que je désires, le problème c'est que j'ai l'impression que la fonction mavilleclientAction n'est pas utilisée puisque sous firebug, il ne me trouve que
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    http://localhost/XXXXXXX/ajax/client
    http://localhost/XXXXXXX/ajax/villeclient
    Merci d'avance à vous tous !!

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    118
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2010
    Messages : 118
    Par défaut
    Cyrux,

    Il faut que tu es une requête SQL spécifique à l'extraction de tes villes.
    en SQL utiliser DISTINCT permet d'éliminer les doublons.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    SELECT DISTINCT ville_client FROM client

  3. #3
    Membre éclairé
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    380
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 380
    Par défaut
    Ok, je tente sa ! Merci !!!

  4. #4
    Membre éclairé
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    380
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 380
    Par défaut
    effectivement sa à l'air de fonctionner, je dis que sa à l'air car je rencontre une erreur en validant la suggestboxvilleclient.
    (ma requête ajax ne me retourne plus qu'une seule proposition de chaque ville, c'est bon signe !!! )

    je tiens au courant de l'évolution

  5. #5
    Membre éclairé
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2009
    Messages
    380
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 380
    Par défaut
    RRRRAAAAAAAAAAAAAHHHHHHHHHHHHHHH !!!!
    Une chose m'échappe !
    il me retourne cette erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Paris' in 'where clause'' in C:\wamp\www\XXXXXXX\library\Zend\Db\Statement\Pdo.php:228 Stack trace: 
    #0 C:\wamp\www\XXXXXXX\library\Zend\Db\Statement\Pdo.php(228): PDOStatement->execute(Array) 
    #1 C:\wamp\www\XXXXXXX\library\Zend\Db\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array) 
    #2 C:\wamp\www\XXXXXXX\library\Zend\Db\Adapter\Abstract.php(468): Zend_Db_Statement->execute(Array) 
    #3 C:\wamp\www\XXXXXXX\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT * FROM c...', Array) 
    #4 C:\wamp\www\XXXXXXX\library\Zend\Db\Adapter\Abstract.php(706): Zend_Db_Adapter_Pdo_Abstract->query('SELECT * FROM c...', Array) 
    #5 C:\wamp\www\XXXXXXX\application\models\TClients.php(34): Zend_Db_Adapter_Abstract->fetchAll('SELECT * FROM c...') 
    #6 C:\wamp\www\XXXXXXX\application\controllers\AjaxController.php(54): TClients->selectDataByID('Lens') 
    #7 C:\wamp\www\XXXXXXX\library\Zend\Controller\A in C:\wamp\www\XXXXXXX\library\Zend\Db\Statement\Pdo.php on line 234
    Il va chercher ma fonction monclientAction alors que c'est la fonction mavilleclientaction qu'il devrait aller chercher !!
    Pourtant les fonctions qui sont appelées dans mon AjaxController sont les bonnes !!!

    Voici la fonction que j'ai rajoutée :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    /**
    	 * Selection de toutes les villes client en supprimant les doublons gràce au distinct
    	 */
    	public function selectDataVille () {
     
    		$sql = "SELECT DISTINCT ville_client FROM client";
     
    		return $this->getAdapter('db')->fetchAll($sql);
    	}
    en remplacement du selectData() dans ma fonction villeclientAction de précédemment.


    EDIT : Honte sur moi, je n'ai pas pensé à regarder mon client.js ... depuis le temps que je le dis... je suis un ...


    il ne me reste qu'a le modifier pour que cela fonctionne, indépendamment l'un de l'autre pas de problème ... allé on je vais pas m'arrêter sur une si bonne lancée, je vais trouver le problème !!!!

  6. #6
    Membre émérite
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2009
    Messages
    736
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2009
    Messages : 736
    Par défaut
    Fais une recherche au pret de tes requete ta oublier de faire les apostrophe pour une variable

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Appel de fonction dans une page JSP
    Par Addouna dans le forum Servlets/JSP
    Réponses: 6
    Dernier message: 09/03/2006, 12h56
  2. Appel de fonction dans une classe
    Par Seth77 dans le forum Langage
    Réponses: 8
    Dernier message: 16/01/2006, 10h32
  3. Appeler une fonction dans un autre cadre !
    Par rich25200 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 01/11/2005, 13h01
  4. Réponses: 7
    Dernier message: 10/09/2005, 16h49
  5. [langage] Appel de fonction dans un lien
    Par drakan dans le forum Langage
    Réponses: 1
    Dernier message: 17/05/2005, 18h30

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