When I try to run the following application in CodeIgniter, I get the following error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/blog.php
Line Number: 1
I've been trying to figure it out for almost an hour and I can't get it to work. My view looks like this:
<?php foreach($data->result() as $row): ?>
<h1><?php echo $row->title; ?></h1>
<p><?php echo $row->post; ?></p>
<?php endforeach; ?>
My controller looks like this:
<?php
class Blog extends CI_Controller {
public function index()
{
$this->load->database();
$data = $this->db->get('posts');
$this->load->helper('url');
$this->load->view('header');
$this->load->view('blog', $data);
$this->load->view('footer');
}
}
Anyone know how to fix this?
$datadoes not set, did you really set this variable?