Welcome Guest, Not a member yet? Register   Sign In
Comments on blog
#10

[eluser]TheFuzzy0ne[/eluser]
Code:
function get_comments()
{
    // Here you're not passing an ID to get_comments().
    // You're also using an extra variable unnecessarily.
    $query = $this->blog_model->get_comments();
    $data['comment'] = $query;

    // This isn't being passed into the view, and has now been called twice.
    // Where is $blog_item coming from?
    $comments = $this->blog_model->get_comments($blog_item->id);

    if(!$comments)
    {
        // This should be handled by your view.
        echo 'No comments';
    }
    else
    {
        $this->load->view('blog/comments',$data);
    }
}

Here are my proposed changes:

get_comments() controller method:
Code:
function get_comments($id = 0)
{
    $data['comments'] = $this->blog_model->get_comments($id);
    $this->load->view('blog/comments', $data);
}

View:
Code:
<?php if ($comments): ?><?php foreach($comments as $com): ?>

<table>
    <tr><td>Date:&lt;?php echo $com['name']; ?&gt;</tr>
    <tr><td>Post:&lt;?php echo $com['comment']; ?&gt;</tr>  
    <tr><td>Date:&lt;?php echo $com['date']; ?&gt;</tr>
</table>&lt;?php endforeach;?&gt;&lt;?php else: ?&gt;

<p>
    There are no comments for this blog.
</p>&lt;?php endif;?&gt;

Your presentation logic should be within your view. Now you view decides what to do (if anything), when there are no comments.


Messages In This Thread
Comments on blog - by El Forum - 04-10-2013, 07:14 PM
Comments on blog - by El Forum - 04-11-2013, 02:54 AM
Comments on blog - by El Forum - 04-11-2013, 05:50 AM
Comments on blog - by El Forum - 04-11-2013, 06:21 AM
Comments on blog - by El Forum - 04-11-2013, 06:28 AM
Comments on blog - by El Forum - 04-11-2013, 06:38 AM
Comments on blog - by El Forum - 04-11-2013, 07:08 AM
Comments on blog - by El Forum - 04-11-2013, 07:12 AM
Comments on blog - by El Forum - 04-11-2013, 07:22 AM
Comments on blog - by El Forum - 04-11-2013, 07:47 AM
Comments on blog - by El Forum - 04-11-2013, 07:49 AM
Comments on blog - by El Forum - 04-11-2013, 09:15 AM
Comments on blog - by El Forum - 04-11-2013, 09:38 AM
Comments on blog - by El Forum - 04-11-2013, 02:50 PM
Comments on blog - by El Forum - 04-11-2013, 06:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB