我想在每一篇文章..但的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