Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Bonjour, j'ai créer une vue zend qui m'affiche sous forme de tableau les résultats d'un recherche sauf que lorsque j'arrive sur la vue de recherche avant de procéder à la première recherche un warning s'affiche sur ma page car rien n'est passé au foreach.
Warning: Invalid argument supplied for foreach()
Merci d'avance Cordialement
Hors ligne
Salut,
Si tu pouvais mettre ton code, ça pourrait nous éclairer.
Essaye de faire un print de ta variable pour voir ce qu'elle contient, car si elle est vide, tu auras ce warning.
Pour passer ta variable à ta vue, utilises le code suivant :
$view = Zend_Registry::get('view'); $this->view->maVariable = $mesDonnees
Hors ligne
et bien au début elle est vide car il n'y a pas de recherche c'est justement ca mon problème
Dernière modification par pierrooot (07-05-2009 10:09:36)
Hors ligne
voici mon code
Controller
function rechercheAction()
{
$this->view->nom = "Résumé d'Interventions";
$form = new rechercheMCForm();
$form->submit->setLabel('Recherche');
$this->view->form = $form;
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
$recherche = '%'.$form->getValue('num_detenu').'%';
$vdetenu = new vdetenu();
$select = $vdetenu->select()->where('num_detenu LIKE ? ', $recherche);
$this->view->vdetenu=$vdetenu->fetchAll($select);
}
}
}
View
<?php
echo $this->form;
?>
<table class="sortable">
<caption><?php echo $this->escape($this->nom); ?></caption>
<thead>
<tr>
<th>Numéro</th>
<th>Etat</th>
<th>Facturation</th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach($this->vdetenu as $vdetenu) :
$num_detenu=$vdetenu->num_detenu;
$etat=$vdetenu->etat;
$facturation=$vdetenu->facturation;
switch ($etat)
{
case pascommence:
$etat="Pas Commencé";
break;
case attente:
$etat="En Attente";
break;
case cours:
$etat="En Cours";
break;
case fini:
$etat="Fini";
break;
}
if($facturation=='1')
{$facturation="oui";}
else
{$facturation="non";}
echo "
<tr>
<td>$num_detenu</td>
<td>$etat</td>
<td>$facturation</td>
";
echo '<td><a href="/center/GererMC/modifierintervention/id_intervention/'.$vdetenu->id_intervention .'"><img src="/center/isc/images/modifier.png"></a></td></tr>';
endforeach;
?> </tbody>
</table>
<table class="sortable">
<caption><?php echo "Résumé de Bon d'Enlèvement ou de Dépôt" ?></caption>
<thead>
<tr>
<th>Numéro</th>
<th>Unité Centrale</th>
<th>Imprimante</th>
<th>Ecran</th>
<th>Autre</th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach($this->vdetenu as $vdetenu) :
$num_detenu=$vdetenu->num_detenu;
$unite_centrale=$vdetenu->unite_centrale;
$imprimante=$vdetenu->imprimante;
$ecran=$vdetenu->ecran;
$autre=$vdetenu->autre;
if($unite_centrale=='1')
{$unite_centrale="oui";}
else
{$unite_centrale="non";}
if($imprimante=='1')
{$imprimante="oui";}
else
{$imprimante="non";}
if($ecran=='1')
{$ecran="oui";}
else
{$ecran="non";}
if($autre=='1')
{$autre="oui";}
else
{$autre="non";}
echo "
<tr>
<td>$num_detenu</td>
<td>$unite_centrale</td>
<td>$imprimante</td>
<td>$ecran</td>
<td>$autre</td>
";
echo '<td><a href="/center/GererMC/modifierbed/id_bed/'.$vdetenu->id_bed .'"><img src="/center/isc/images/modifier.png"></a></td></tr>';
endforeach;
?> </tbody>
</table>
<table class="sortable">
<caption><?php echo "Résumé des Fiches de Prêt" ?></caption>
<thead>
<tr>
<th>Numéro</th>
<th>Désignation</th>
<th>Date du prêt</th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach($this->vdetenu as $vdetenu) :
$num_detenu=$vdetenu->num_detenu;
$designation=$vdetenu->designation;
$date_pret=$vdetenu->date_pret;
echo "
<tr>
<td>$num_detenu</td>
<td>$designation</td>
<td>$date_pret</td>
";
echo '<td><a href="/center/GererMC/modifierpret/id_pret/'.$vdetenu->id_pret .'"><img src="/center/isc/images/modifier.png"></a></td></tr>';
endforeach;
?> </tbody>
</table>
Hors ligne
Hello,
Initialises ta variable en début d'action :
$vdetenu = array();
Si ton formulaire est valide, elle sera remplacée par ton Rowset (qui implémente ArrayAccess).
A+
Hors ligne
$vdetenu = array(); ne change rien au niveau de mon warning
Hors ligne
Hello,
Si tu ne l'envoies pas à ta vue, c'est sûr !
function rechercheAction() { $vdetenuResults = array(); $this->view->nom = "Résumé d'Interventions"; $form = new rechercheMCForm(); $form->submit->setLabel('Recherche'); $this->view->form = $form; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $recherche = '%'.$form->getValue('num_detenu').'%'; $vdetenu = new vdetenu(); $select = $vdetenu->select()->where('num_detenu LIKE ? ', $recherche); $vdetenuResults=$vdetenu->fetchAll($select); } } $this->view->vdetenu=$vdetenuResults; }
A+
Hors ligne
merci j' n'ai pas fait attention Merci
Je voulais également vous demander un autre point j'ai créer une vu sql qui s'appelle vdetenu qui reprend des informations de trois tables différentes mais dans mon affichage celui dont j'ai mis le code précédent je n'arrive pas à afficher que le résultat d'un tableau donc si un détenu ne possède pas des informations des trois tables les informations ne s'affichent pas . je planche dessus depuis un moment maintenant mais toujours bloqué.
Cordialement
Hors ligne
Hello,
LEFT JOIN au lieu d'INNER JOIN
A+
Hors ligne
mais left join ne fonctionne pas en sql ? cela fonctionne pour faire des requêtes seulement ?
Hors ligne