私はすべての記事でコメントを数えたいと思っていますが、foreachループ間のコメントカウンタは...正確にコメントを数えることはできません...だからループは必要ですがカウンタのループは必要ありませんforeachループでカウントを見つける方法は?
articles_controller.php
$count = $this->Article->Comment->find(
'count', array('conditions' => array('Comment.status' => 1))
);
記事/ index.ctp
<?php
// initialise a counter for striping the table
$count = 0;
// loop through and display format
foreach($articles as $article):
// stripes the table by adding a class to every other row
$class = (($count % 2) ? " class='altrow'": '');
// increment count
$count++;
?>
<?php
echo $html->link(
$article['Article']['title'],
array('action' => 'view', $article['Article']['id'])
);
?>
<!-- date and comment counter -->
<p class="entry-meta">
<span class="date"><?php echo $article['Article']['created']; ?></span> <span class="meta-sep">|</span>
<span class="comments-link">
<!-- here i will put the comment counter -->
<a href="declining-health.html#respond"> <?php echo $count ['Comment'];>Comments</a>
</span>
</p>
<?php endforeach; ?>
abba thannnnnnks..moreありがとう..素晴らしいソリューション.. – user1080247