遇到PHP错误严重性:Notice消息:Undefined属性:stdClass::$comment_count文件名:


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

我的view/blog/index.php第35行如下:

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

我在表注释中做了一列,作为comment_id仍然不能工作

,在我的model/blog_model.php中,它是一个函数:

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

Thanks in advance

你把记号弄混了。问题不是很清楚,但是如果你设置了一个数组索引,比如…

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

我假设将$count作为$post传递到您的视图中,并尝试像这样访问…

$post->comment_count 

它不起作用,因为这不是数组符号。正确的是…

$post['comment_count']

如果$post$count是不同的对象,那么你需要做…

$count['comment_count']