[eluser]cirox![/eluser]
Hi everyone,
I'm new to both ci & php and I need your help. I've successfully followed the online video - blog system tutorial - and I'm now attempting to add some more functionality to it as an exercise.
Namely, I'm trying to get the "Comments" link to show the number of comments, e.g. "Comments(8)".
I can't think of an easy way to do it, without violate (what's my understanding of) MVC.
I'd be grateful if someone could tell me a straightforward of doing it.
Thanks.
blog_view.php
Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $title; ?></h1>
<?php foreach($query->result() as $row): ?>
<h3><?php echo $row->title ?></h3>
<p><?php echo $row->body ?></p>
<p><?php echo anchor('blog/comments/'.$row->id,'Comments'); ?></p>
<hr />
<?php endforeach; ?>
</body>
</html>
blog.php
Code:
<?php
class Blog extends Controller {
function Blog()
{
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
}
function index()
{
$data['title'] = "My Blog Title";
$data['heading'] = "My Blog Heading";
$data['query'] = $this->db->get('entries');
$this->load->view('blog_view', $data);
}
function comments()
{
$data['title'] = "My Comment Title";
$data['heading'] = "My Coment 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']);
}
}
?>