• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cant load my view

#5
[eluser]cahva[/eluser]
[quote author="lucasvm" date="1303428949"]
but if i do echo $data on my index view i get variable undefined, why?[/quote]

When you pass $data to your view, there wont be a variable called $data in your view(unless you have $data['data'] set). From your example you would have $titulo, $contenido and $autor at your disposal.

But there is an error in your controller also. You iterate through the result and set the variables with the same name over and over again. You would only have the last $titulo etc. from the result.

Just pass the whole result to your view(and btw, you should put the db calls to model):
Code:
// In controller
$query = $this->db->query('myquery');
$data['rows'] = $query->result();

$this->load->view('header');
$this->load->view('principal',$data);
$this->load->view('footer');

In view:
Code:
<table>
    <tr>
        <th> Titulo </th>
        <th> Contenido </th>
        <th> Autor </th>
    </tr>
&lt;?php foreach ($rows as $row): ?&gt;
    <tr>
        <td>&lt;?= $row->titulo ?&gt;</td>
        <td>&lt;?= $row->contenido ?&gt;</td>
        <td>&lt;?= $row->autor ?&gt;</td>
    </tr>
&lt;?php endforeach; ?&gt;
</table>


Messages In This Thread
Cant load my view - by El Forum - 04-21-2011, 11:00 AM
Cant load my view - by El Forum - 04-21-2011, 11:32 AM
Cant load my view - by El Forum - 04-21-2011, 12:35 PM
Cant load my view - by El Forum - 04-21-2011, 04:13 PM
Cant load my view - by El Forum - 04-21-2011, 05:56 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.