Welcome Guest, Not a member yet? Register   Sign In
noob: trying to build on "blog tutorial"
#1

[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>&lt;?php echo $title; ?&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;

blog.php
Code:
&lt;?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']);
    }
}

?&gt;


Messages In This Thread
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 12:05 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 12:23 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 12:43 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 12:46 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 01:17 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 01:20 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 01:30 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 01:47 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 01:53 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 01:59 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-27-2008, 04:10 PM
noob: trying to build on "blog tutorial" - by El Forum - 05-28-2008, 03:25 AM
noob: trying to build on "blog tutorial" - by El Forum - 05-29-2008, 03:27 AM
noob: trying to build on "blog tutorial" - by El Forum - 05-29-2008, 09:24 PM
noob: trying to build on "blog tutorial" - by El Forum - 07-23-2008, 04:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB