I am trying to pass from my controller to the view like so…
public function playerslist()
{
$this->load->database();
$data = $this->db->get('skaters');
$this->load->helper('url');
$this->load->view('playerslist', $data);
}
and in my view…
<?php echo $data; ?>
but I get this error…
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/playerslist.php
Line Number: 76
What am I doing wrong?
What I would like to do with this data is put in a foreach statement and display everything in the $data array
foreach($data as $value => $key){
echo $key . "<br/>";
}
Thanks,
J
You cannot access
$datadirectly from your view. The$datayou pass to your view has to be an associative array. The keys will then be converted to variables in your view.For example:
Then, in your view, those will be converted to variables:
If you want to access the data in its original format, pass that into the associative array: