Welcome Guest, Not a member yet? Register   Sign In
A little help for a newbie
#1

[eluser]A_funs[/eluser]
ok So I have this code in my controller, and I know $thisdat is defined, it is an array of arrays if I print_r() it.

Code:
$query = $this->db->get('meta');
  
  $thisdat = $query->result_array();
  
  $this->load->view('header', $thisdat);

However, I get an error when loading the view:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: thisdat

Filename: views/header.php

Line Number: 3

this is my view code:

Code:
<?php

foreach ($thisdat as $row)
{
    echo $row['title'];
}
?>

Any help or guidance would be very much appreciated, thanks!
#2

[eluser]fcxxff[/eluser]
You should do this:
Code:
$query = $this->db->get('meta');
  
  $thisdat['data'] = $query->result_array();
  
  $this->load->view('header', $thisdat);
And in view, You should be able to manipulate not with $thisdat but with $data so:
Code:
<?php

print_r($data);

?>
#3

[eluser]A_funs[/eluser]
Hey Thanks, that worked, could you give me a little explanation as to why what you did works though? As opposed to what I had been doing before?
#4

[eluser]fcxxff[/eluser]
Grab the link:
http://ellislab.com/codeigniter/user-gui...views.html
Theres everything about it.
Good luck!
#5

[eluser]CroNiX[/eluser]
The array that gets passed to the view must be an associative array as CI will extract() that array into variables in the view so you can access its keys using $key.
Code:
$data['thisdat'] = 'This data';
$data['otherdat'] = 'Some other data';
$this->load->view('view_file', $data);

...In view

Code:
echo $thisdat; //outputs 'This data'
echo $otherdat; //outputs 'Some other data'




Theme © iAndrew 2016 - Forum software by © MyBB