簡體   English   中英

遇到 PHP 錯誤嚴重性:通知消息:未定義的屬性:stdClass::$comment_count 文件名:blog/index.php 行號:35

[英]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,
    );

提前致謝

你正在混淆你的符號。 問題不是很清楚,但是如果您設置了一個數組索引,例如...

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

我假設將$count作為$post傳遞到您的視圖中並嘗試像這樣訪問......

$post->comment_count 

它不會工作,因為這不是數組表示法。 正確的應該是..

$post['comment_count']

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

$count['comment_count']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM