简体   繁体   中英

A PHP Error was encountered Severity: Notice Message: Undefined property: stdClass::$comment_count Filename: blog/index.php Line Number: 35

My line number 35 of view/blog/index.php is as:

<a href="<?php echo base_url().'post/'.$post->entry_id.'#comments';?>" class="comments">Comments (<?php echo $post->comment_count;?>)</a> 

I have made a column in table comment as comment_id still its not working

and in my model/blog_model.php it is a function as:

$count = array(
        'comment_count' => $total_count,
    );

Thanks in advance

You are mixing up your notations. Question isnt very clear but if you have set an array index like...

$count = array(
    'comment_count' => $total_count,
);

And I assume passing $count as $post into your view and trying to access like this...

$post->comment_count 

It wont work as this is not array notation. Correct would be..

$post['comment_count']

If $post and $count are different objects then you need to do..

$count['comment_count']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM