我想在每一篇文章..但的foreach loop..so我不能正确计算评论的评论柜台的地方来算的意见,所以,我想循环,但我不需要循环的计数器如何在foreach循环中查找count?
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 ..更多谢谢..更好的解决方案.. – user1080247 2011-12-30 20:37:30