[eluser]Unknown[/eluser]
Hello,
I am a newbie to CI, just started. I want to make a blog application, and so I want to get all my dummy blog entries out of the database (made with scaffolding), but when i load the page i get this:
Code:
Blog heading
Fatal error: Call to a member function result() on a non-object in C:\wamp\www\ci\system\application\views\blog_view.php on line 18
This may be a noob-problem, but it's driving me nuts. Why do I get this error?
Here is my controller (blog.php):
Code:
<?php
class Blog extends Controller{
function __construct()
{
parent::Controller();
$this->load->helper('url');
}
function index()
{
// General
$data['title'] = 'Blog title';
$data['heading'] = 'Blog heading';
// Load blog_model and save the get_all_entries function result
$this->load->model('Blog_model');
$data['entries'] = $this->Blog_model->get_all_entries();
// Bypass Blog_model
//$data['entries'] = $this->db->get('entries');
// Load view(s)
$this->load->view('blog_view', $data);
}
function comments()
{
$data['title'] = 'Comments title';
$data['header'] = 'Comments heading';
}
}
?>
Here is my model (blog_model.php):
Code:
<?php
class Blog_model extends Model{
function Blog_model()
{
parent::Model();
}
function get_all_entries()
{
$query = $this->db->get('entries');
return $query->result();
}
}
?>
And here is my view (blog_view.php):
[code]
<html>
<head>
<title><?php echo $title;?></title>
<meta name="author" content="" />
<meta name="copyright" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="abstract" content="" />
<meta name="robots" content="index,follow" />
<meta name="language" content="" />
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<h1><?php echo $heading;?></h1>
<?php foreach($entries->result() as $row): ?>
<h2><?php echo $row['title'];?></h2>
<p><?php echo $row['content'];?></p>
<hr>
<?php endforeach; ?>
</body>
</html>
[/code]
I really hope you can help me out with this. Thank you.
Best regards.