Zwrócenie wyniku do szablonu w php

0

Chce wyswietlic w smarty zawartosc tablicy $result

W tablicy sa jakies elementy, przykladowo:

array(1) { ["result"]=> array(2) { [0]=> object(stdClass)#25 (8) { ["id"]=> string(1) "1" ["name"]=> string(7) "Moduły" ["description"]=> string(38) "Moduł dodania nowych funkcjonalności" ["number"]=> string(3) "000" ["file_start"]=> string(11) "modules.php" ["position"]=> string(1) "0" ["active"]=> string(1) "1" ["dateAdd"]=> string(19) "2017-08-19 1710" } [1]=> object(stdClass)#26 (8) { ["id"]=> string(1) "9" ["name"]=> string(4) "Test" ["description"]=> string(7) "Testowy" ["number"]=> string(3) "001" ["file_start"]=> string(9) "index.php" ["position"]=> string(1) "0" ["active"]=> string(1) "1" ["dateAdd"]=> string(19) "2017-08-19 1924" } } }

Lecz gdy probuje to wyswietlic to jest pusto i nie zwraca zadnego bledu. Jakies podpowiedzi?

<table>
    <tr>
        <th>ID</th>
    </tr>
{foreach from=$result key=i item=row }

  
  <tr>
      <td>{$row.id}</td>
      <td>{$row.number}</td>

  </tr>
{/foreach}
</table>
0
array(1) {
    ["result"]=> array(2) {
        [0]=> object(stdClass)#25 (8) 
        {
            ["id"]=> string(1) "1"     
            ["name"]=> string(7) "Moduły"   
            ["description"]=> string(38) "Moduł dodania nowych funkcjonalności"   
            ["number"]=> string(3) "000"  
            ["file_start"]=> string(11) "modules.php"    
            ["position"]=> string(1) "0"   
            ["active"]=> string(1) "1"    
            ["dateAdd"]=> string(19) "2017-08-19 17:08:10" 
        }
        [1]=> object(stdClass)#26 (8) 
        {
            ["id"]=> string(1) "9"     
            ["name"]=> string(4) "Test"     
            ["description"]=> string(7) "Testowy"   
            ["number"]=> string(3) "001"  
            ["file_start"]=> string(9) "index.php"   
            ["position"]=> string(1) "0"  
            ["active"]=> string(1) "1"   
            ["dateAdd"]=> string(19) "2017-08-19 19:08:24" 
        }
    }
 }

https://www.smarty.net/docs/en/language.variables.tpl#language.variables.objects

    {foreach $nazwaZmiennejWktórejTrzymaszTablice['result'] as $k => $resultValue}
        {$resultValue->id}
    {/foreach}

0

conttroler

 $data['result'] = $this->model_test->oSelect();
 $this->smarty->assign('result', $data);

model

 function oSelect()
    {
        $this->db->select('*');
        $query = $this->db->get('modules');
        return $query->result();
    }

mam cos takiego

0

Zmodyfikowanie w taki sposob, bo chyab o to Ci chodziło nic nie zmienia:

 {foreach $result as $k => $resultValue}
        {$resultValue->id}
    {/foreach}
0

Nie wiem jaką masz teraz strukturę, wcześniej w zmiennej miałeś tablicę jednoelementową z indeksem 'result' robiłeś na tym jednym elemencie pętle foreach, teraz prawdopodobnie robisz dokładnie to samo, nie wiem co ci tam zwraca twoje zapytanie.

W zwróconej tablicy dostajesz tablice obiektów, do pol obiektu możesz się dostać używając operatora -> a nie kropki, której możesz używać tylko do elementów tablicy

Sprawdź jak wygląda struktura tego co masz w zmiennej $result po której próbujesz iterować i problem ci się sam rozwiąże.

Albo iteruj po $result['result] albo wywal ten klucz jeżeli go nie potrzebujesz i zapisz listę, wynik zapytania bezpośrednio do zmiennej

eg.

 $data = $this->model_test->oSelect();
 $this->smarty->assign('result', $data);

  {foreach $result as $resultValue}
    {$resultValue->id}
  {/foreach}

1 użytkowników online, w tym zalogowanych: 0, gości: 1