[eluser]karloff[/eluser]
hi guys, probably a simple answer here
I have created a simple blog which worked fine until I tried to include the blog post with my comments any ideas?
the error
Quote:Fatal error: Call to a member function on a non-object in c:\instantrails-2.0-win\www\system\application\views\comment_view.php on line 8
here is my code
application/blog.php
Code:
<?php
class Blog extends Controller {
function blog ()
{
parent::Controller();
$this->load->scaffolding('entries');
$this->load->helper('form');
$this->load->helper('url');
}
function index ()
{
$data['title'] = "Blog";
$data['heading'] = "Blog";
$data['query'] = $this->db->get('entries');
$this->load->view('blog_view', $data);
}
function posts ()
{
}
function comments ()
{
$this->db->where('id', $this->uri->segment(3));
$query = $this->db->get('entries');
$data = $query->result();
// This shold have been a JOIN
$this->db->where('entry_id', $this->uri->segment(3));
$query2 = $this->db->get('comments');
$data2 = $query2->result();
$this->load->view('comment_view', array('data' => $data, 'data2' => $data2));
}
function comments_insert ()
{
$this->db->insert('comments', $_POST);
redirect('blog/comments/'.$_POST['entry_id']);
}
}
?>
views/comment_view.php
Code:
<?=$this->load->view('header')?>
<?php foreach ($data as $row): ?>
<h3><?=$row->title ?></h3>
<p><?=$row->body ?></p>
<?php endforeach ?>
<?php if ($query2->num_rows() > 0): ?>
<?php foreach($query->result() as $row2): ?>
<div class="block">
<h3><?=$row2->body?></h3>
<p><?=$row2->author?></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
<div class="block">
<p><?=anchor('blog', 'back to blog');?></p>
<?=form_open('blog/comments_insert');?>
<?=form_hidden('entry_id', $this->uri->segment(3));?>
<p><textarea name="body" rows="10"></textarea></p>
<p><input type="text" name="author" /></p>
<p><input type="submit" value="Submit Comment" ?></p>
</form>
</div>
<?=$this->load->view('footer')?>