Zend Framework Requête paramétrée
Bonjour ;
Pouvez-vous m’aider ?
Lorsque j’essaye d’afficher le résultat d’une requête paramétrée je reçois le message suivante :
Citation:
Warning: Invalid argument supplied for foreach() in C:\wamp\www\cdfc\application\modules\admin\views\scripts\consencai\encais .phtml on line 36
La ligne 36 correspond à la première ligne dans l’extrait du fichier encais .phtml ci dessous
Merci
Modèle :
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
|
<?php
class Admin_Model_DbTable_Consencai extends Zend_Db_Table_Abstract {
protected $_name = 'tconsencai';
protected $_primary = 'id_consecai';
public function pargroupe($parametres = NULL) {
try {
$select = $this->select();
if ($parametres) {
$select->where($this->getAdapter()->quoteIdentifier("libel_groupe_consencai").'=?',$parametres);
->order('np_eleve_consencai ASC');
}
$encaiRows = $this->fetchAll($select);
$rows = array();
foreach ($encaiRows as $encaiRow) {
$rows[] = new Admin_Model_Consencai($encaiRow);
}
return $rows;
}
catch (Exception $e) {
echo "consConsencai<br />";
echo $e->getMessage();
exit;
}
} |
Contrôleur :
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
|
<?php
class Admin_ConsencaiController extends Zend_Controller_Action {
public function init() { }
public function indexAction() { }
public function encaisAction() {
$form = new Admin_Form_Conscours();
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
$parametres = $formData['libel_groupe'];
$donnees = new Admin_Model_DbTable_Consencai();
$this->view->rows = $donnees->pargroupe($parametres);
$this->view->texte=$texteAAfficher;
}
}
public function afficherAction() {
$this->view->headLink()
->appendStylesheet($this->view->baseUrl().'/styles/formlogin.css');
$form = new Admin_Form_Conscours();
$this->view->form = $form;
$this->view->message = '';
}
} |
Formulaire :
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
|
<?php
class Admin_Form_Conscours extends Zend_Form {
public function init() {
$this->setMethod('post')
->setName('consultationcours')
->setAttrib('name', 'conscours');
$groupeTab = new Admin_Model_DbTable_Groupe();
$groupeRows = $groupeTab->getGroupes();
$groupes = array();
foreach ($groupeRows as $row) {
$groupes[$row->libel_groupe] = $row->libel_groupe;
}
$groupe = new Zend_Form_Element_Select('libelgroupe');
$groupe->setLabel('Groupe : ')
->setMultiOptions($groupes)
->setValue(0)
->getDecorator('label')->setOption('tag', NULL);
$this->addElement($groupe);
$this->setDecorators(array(array('ViewScript',
array('viewScript' => 'consultscript.phtml'))));
}
} |
consultscript.phtml (Pour afficher le formulaire) :
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
|
<form action="<?php echo $this->escape($this->element->getAction()); ?>"
method="<?php echo $this->escape($this->element->getMethod()); ?>"
name="<?php echo $this->escape($this->element->getAttrib('name')); ?>"
class="formconscours">
<table>
<tr>
<td align="center" COLSPAN=2><b>
Veuillez choisir le parametre adequoat </b>
</td>
<td align="center"><b>Cliquez sur le lien correspondant a votre choix </b>
</td>
</tr>
<tr>
<td align="center" COLSPAN=2></td>
<td align="right"></td>
</tr>
<tr>
<td align="right">
<?php echo $this->element->libelgroupe->renderLabel(); ?>
</td>
<td>
<?php echo $this->element->libelgroupe->renderViewHelper(); ?>
</td>
<td>
<div align="center">
<a href="<?php echo $this->url(array('module'=>'admin',
'controller'=>'consencai',
'action'=>'encais'),
'default', true) ?>">
Consultation par groupe
</a>
</div>
</td>
</tr>
</table>
</form> |
afficher.phtml :
Code:
1 2 3 4 5 6
|
<center><h1>Consultations des encaissements</h1></center>
<br><br>
<?php
$this->form->setAction($this->url());
echo $this->form; |
Extrait du consultscript.phtml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
...........
<?php foreach ($this->rows as $infoEncaissements) { ?>
<tr>
<td class="colg1"align="center">
<?php echo $infoEncaissements->np_professeur; ?>
</td>
<td class="colg1"align="center">
<?php echo $infoEncaissements->np_eleve_consencai; ?>
</td>
........... |
Zend Framework Requête paramétrée
Bonjour,
Premièrement je remercie 5h4rk et Sereine
Effectivement Sereine au niveau du dernier morceau du code je me suis trompé du nom du fichier , il s’agit de encais .phtml ceci d’une part d’autre part même si je remplace le modèle consencai.php par le code ci-dessous le message d’erreur est toujours le même.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
<?php
class Admin_Model_DbTable_Consencai extends Zend_Db_Table_Abstract {
protected $_name = 'tconsencai';
protected $_primary = 'id_consecai';
public function pargroupe($parametres = NULL) {
try {
if ($parametres) {
return $this->fetchRow($this->select()
->where($this->getAdapter()->quoteIdentifier("libel_groupe_consencai").'=?',$parametres);
->order('np_eleve_consencai ASC');
}
catch (Zend_Db_Exception $e) {
echo "consConsencai<br />";
printf("Erreur SQL :%s",$e->getMessage());
exit;
}
}
}
} |
Extrait du encais.phtml :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
...........
<?php foreach ($this->rows as $infoEncaissements) { ?>
<tr>
<td class="colg1"align="center">
<?php echo $infoEncaissements->np_professeur; ?>
</td>
<td class="colg1"align="center">
<?php echo $infoEncaissements->np_eleve_consencai; ?>
</td> |
Merci
Zend Framework Requête paramétrée
La définition de la table sur laquelle j’essaye d'exécuter la requête est :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| CREATE TABLE IF NOT EXISTS `tconsencai` (
`id_consencai` int(11) NOT NULL AUTO_INCREMENT,
`np_professeur` varchar(60) NOT NULL,
`np_eleve_consencai` varchar(60) NOT NULL,
`libel_groupe_consencai` varchar(60) NOT NULL,
`tprestation_consencai` smallint(6) NOT NULL DEFAULT '0',
`prix_consencai` float NOT NULL ,
`montantregle_consencai` float NOT NULL ,
`treglement_consencai` smallint(6) NOT NULL DEFAULT '0',
`dtreglement_consencai` date,
`com_consencai` varchar(100) NOT NULL,
PRIMARY KEY (`id_consencai`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=21 ; |
L’équivalent de ma requête en sql est:
Code:
SELECT * FROM `tconsencai` WHERE `libel_groupe_consencai` LIKE 'parametre'
parametre je doit le récupérer du formulaire à l'aide de la méthode post