Welcome Guest, Not a member yet? Register   Sign In
Simple Question: Expanding on the Blog Tutorial
#1

[eluser]MT206[/eluser]
Hi, I am new to CI and I am having trouble wrapping my head around some simple things. Right now all I am trying to do is just put the number of comments a blog post has under the post but for the life of me I cant figure out how to. I understand how you would do it with just PHP but obviously the point is to have CI make life easier so I am trying to use it. Any help would be much appreciated. Thanks

For people not familiar with the blog video tutorial here is the controller code:

Code:
function Blog(){
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('form');
    }
    function index(){
        $data['title'] = 'Mike\'s Blog';
        $data['heading'] = 'Mike\'s Blog Heading';
        $data['query'] = $this->db->get('entries');
        $this->load->view('blog_view', $data);
    }
    function comments(){
        $data['title'] = 'Mike\'s Blog';
        $data['heading'] = 'Mike\'s Comment Heading';
        $this->db->where('entry_id', $this->uri->segment(3));
        $data['query'] = $this->db->get('comments');
        
        
        $this->load->view('comment_view', $data);
    }
    function comment_insert(){
        $this->db->insert('comments', $_POST);
        redirect('blog/comments/' . $_POST['entry_id']);
    }
}
?>


and the blog view code:
Code:
<html>
    <head>
        <title><?php echo $title; ?></title>
    </head>
    <body>
    <h1>&lt;?php echo $heading; ?&gt;</h1>
        &lt;?php foreach($query->result() as $row): ?&gt;
            <h3>&lt;?php echo $row->title; ?&gt;</h3>
            <p>&lt;?php echo $row->body; ?&gt;</p>
            
            <p>&lt;?php echo anchor('blog/comments/' . $row->id, 'Comments'); ?&gt;</p>
            <hr>
        &lt;?php endforeach; ?&gt;
    &lt;/body&gt;
&lt;/html&gt;


Messages In This Thread
Simple Question: Expanding on the Blog Tutorial - by El Forum - 02-13-2010, 05:56 AM
Simple Question: Expanding on the Blog Tutorial - by El Forum - 02-13-2010, 06:43 AM
Simple Question: Expanding on the Blog Tutorial - by El Forum - 02-13-2010, 03:59 PM
Simple Question: Expanding on the Blog Tutorial - by El Forum - 02-14-2010, 01:59 PM
Simple Question: Expanding on the Blog Tutorial - by El Forum - 02-15-2010, 04:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB