[eluser]Arministrator[/eluser]
First off, Hi great Codeigniter community. I've been present as a guest on forums for a while now, but this is my first post.
I've browsed and searched and googled first, for a solution of what should be a tiny problem for you guys, but in the end I had to start this topic.
I'm using a really simple getAll function in my model to retrieve data. That function is called from a controller and passes the data as an array to the view. And it all works fine on localhost (WAMP), but fails online. I'm baffled.
The Model:
Code:
<?php
class Data_model extends CI_Model {
function getAll() {
$q = $this->db->get('data');
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
}
?>
The Controller:
Code:
<?php
class Site extends CI_Controller {
function index() {
$title['title'] = "Site title";
$this->load->model('data_model');
$data['rows'] = $this->data_model->getAll();
$this->load->view('header', $title);
$this->load->view('content', $data);
$this->load->view('footer');
}
function Project() {
$this->load->view('project');
}
}
?>
The View:
Code:
<?php foreach($rows as $r):?>
<h1><?php echo $r->title;?></h1>
<p><?php echo $r->content;?></p>
<p><?php echo $r->author;?></p>
<?php endforeach; ?>
All of this stuff is more or less from the Net Tuts CI series. I've seen this problem posted in comments, but no solution. And this is really a tripping point for me, because how do I know that I'm doing anything right (or wrong) if it works locally and fails online.
Again, sorry if this has been discussed before.
EDIT: Oh, this is the error I get:
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/content.php
Line Number: 2