2012-07-04 1 views
0

J'utilise le smarty tpl.smarty tpl foreach

Maintenant, j'ai un code php et je veux l'utiliser dans tpl:

Tis est la sortie du tableau.

stdClass Object 
(
[Status] => success 
[Time] => 2011-01-01 12:00:00 
[IP] => 12.34.56.789 
[Count] => 1 
[Filter] => stdClass Object 
    (
     [Sort] => ProductCode 
     [Order] => DESC 
     [Search] => 
     [ProductCode] => P001 
     [ProductType] => 
    ) 

[Result] => stdClass Object 
    (
     [Products] => Array 
      (
       [0] => stdClass Object 
        (
         [Identifier] => 1 
         [ProductCode] => test 
         [ProductName] => test 
        ) 

      ) 

    ) 

Tis est le code php qui fonctionne:

foreach ($product_list->Result->Products as $product) { 
     echo $product->ProductName; 
} 

J'utilise le suivi du code tpl, mais cela ne fonctionne pas

  //in php 
    $smarty->assign("data", $product_list); 

    //in tpl file 
    {foreach item=item from=$data} 

<tr> 
    <td align="center">{$item.Result->Products->ProductName}</td> 
    <td align="center"></td> 
    <td align="center"></td> 
    <td align="center"><a href="" class="usuallink">{$header.order}</a></td> 
</tr> 
{/foreach} 

Quelqu'un maintenant comment je peux résoudre ce problème?

Répondre

1

Code de travail de php ressemblera à ceci:

{foreach from=$data->Result->Products item=item} 
    {$item->ProductName} 
{/foreach} 

en smarty3 il peut regarder encore plus comme php pur:

{foreach $data->Result->Products as $item} 
    {$item->ProductName} 
{/foreach} 
+0

Merci! Ça marche! – tom