appel de fonction dans Ajaxcontroller
Bonjour à tous,
alors voila, mon problème est simple :
j'ai ce AjaxController :
Code:
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é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> ';
$html .= '<a href="'.$this->view->url(array('controller'=>'index'
,'action'=>'supprimer'
, 'id'=>$client->numero_client))
.'">Supprimer</a> ';
$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é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> ';
$html .= '<a href="'.$this->view->url(array('controller'=>'index'
,'action'=>'supprimer'
, 'id'=>$client->numero_client))
.'">Supprimer</a> ';
$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:
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 ... :oops:
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:
1 2
| http://localhost/XXXXXXX/ajax/client
http://localhost/XXXXXXX/ajax/villeclient |
Merci d'avance à vous tous !!