Re: Utiliser l'api allociné dans xoopstube | Titre du sujet : Re: Utiliser l'api allociné dans xoopstube par slider84 sur 22/12/2014 21:32:00
Un petit exemple basique pour t'aider à comprendre:
Dans ton script php:
// ta requête
$sql= $xoopsDB->query('SELECT champ1,champ2,champ3,champ4 FROM '.$xoopsDB->prefix('mytable');
// construction du tableau de valeurs à passer
while ( $myrow = $xoopsDB->fetchArray($sql) ) {
$myarray =array();
$myarray['champ1'] = $myrow['champ1'];
$myarray['champ2'] = $myrow['champ2'];
$myarray['champ3'] = $myrow['champ3'];
$myarray['champ4'] = $myrow['champ4'];
//passage du tableau de valeurs pour chaque enregistrement vers
//la variable smarty (ici elle sera nommée 'mysmarty').
//Ajout à la smarty pour chaque enregistrement trouvé
$xoopsTpl->append('mysmarty', $myarray);
}
Dans ton template, affichage des valeurs du tableau contenues dans la variable smarty (pour chaque enregistrement):
<{foreach item=mysmartyitem from=$mysmarty}>
<ul>
<li>Mon champ 1: <{$mysmartyitem.champ1}></li>
<li>Mon champ 2: <{$mysmartyitem.champ2}></li>
<li>Mon champ 3: <{$mysmartyitem.champ3}></li>
<li>Mon champ 4: <{$mysmartyitem.champ4}></li>
</ul>
<br><hr>
<{/foreach}>
Astuce: Tu mets le mode 'Debug pour smarty et template' actif dans l'administration de Xoops pour voir comment est construite ta smarty
|
|