Tuesday, July 8, 2008

Using a helper to count items in an iterator

today the example is for a site that organizes web links and associates them with tags. In order to count the tags while listing data, we do something like this:



<{ITERATOR links}>
<{IF (LinkHelper::Count_tags_by_link_id(id) > 0)}>
<{ITERATOR get_tags()}>
<{name}><br />


public static function Count_tags_by_link_id( $link_id ) {

FUSE::Require_model( 'Link' );

$link = new Link();
$link->id = $link_id;

return $link->tags->count_all();


public function get_tags() {
return $this->tags->fetch_all();

No comments: