|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Overdoze Smarty n00b
Joined: 25 Aug 2010 Posts: 1
|
Posted: Sat Nov 20, 2010 7:35 am Post subject: récupérer une variable dans fichier tpl |
|
|
Bonjour
j'ai découvert smarty lorsque j'ai utilisé le cms prestashop mais la notion php/tpl m'est encore flou.
pour chaque fichier tpl , un fichier php est associé pour le traitement des données tq les requêtes sql pour les afficher ensuite dans le tpl.
par exemple j'ai fait une requête sql pour récupérer des variables de ma table par ce bout de code Code: | private function GetAvailableAttributes($id_product, $id_lang)
{
return Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'product_attribute` p_a
LEFT JOIN `'._DB_PREFIX_.'product_lang` p_l ON(p_a.`id_product` = p_l.`id_product`)
WHERE p_a.`id_product` = '.intval($id_product).'
AND p_l.`id_lang` = '.intval($id_lang).'
AND p_a.`quantity` >= 1');
} |
puis j'ai affecté le résultat comme ça Code: | $result = Product::GetAvailableAttributes($id_product, $id_lang);
$smarty->assign('tabResult',$result); |
et pour l'afficher j'ai utiliser une boucle foreach Code: | {foreach from=$tabResult item='decl'}
{$decl.id_product_attribute}{$decl.quantity}
{/foreach} |
mais ça m'affiche rien ,la variables $tebResult est vide.
je voulais juste me dire si l'affectation de résultat (code 2) ce fait de cette manière avec smarty??
je me sèche
Merci d'avance |
|
Back to top |
|
Gowser Smarty Pro
Joined: 19 Feb 2008 Posts: 104 Location: Nantes (France)
|
Posted: Sat Nov 20, 2010 5:25 pm Post subject: |
|
|
Bonjour,
L'assignation de la variable dans le deuxième morceau de code est propre (tu pourrais même directement faire $smarty->assign('tabResult',Product::GetAvailableAttributes($id_product, $id_lang)); pour gagner encore en assignation de variable mais bon la c'est du chipotage ).
Es-tu sur que la requête te ramène des enregistrements ?
Quel résultat cela te donne si tu fais un print_r de ta variable $result ? |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|