Zend_Tag

Introduction

Zend_Tag is a component suite which provides a facility to work with taggable Items. As its base, it provides two classes to work with Tags, Zend_Tag_Item and Zend_Tag_ItemList. Additionally, it comes with the interface Zend_Tag_Taggable, which allows you to use any of your models as a taggable item in conjunction with Zend_Tag.

Zend_Tag_Item is a basic taggable item implementation which comes with the essential functionality required to work with the Zend_Tag suite. A taggable item always consists of a title and a relative weight (e.g. number of occurrences). It also stores parameters which are used by the different sub-components of Zend_Tag.

To group multiple items together, Zend_Tag_ItemList exists as an array iterator and provides additional functionality to calculate absolute weight values based on the given relative weights of each item in it.

Example #1 Using Zend_Tag

This example illustrates how to create a list of tags and spread absolute weight values on them.

  1. // Create the item list
  2. // Assign tags to it
  3. 'title' => 'Code', 'weight''title' => 'Zend Framework', 'weight''title' => 'PHP', 'weight' => 5));
  4.  
  5. // Spread absolute values on the items
  6. // Output the items with their absolute values
  7. "%s: %d\n", $item->getTitle(), $item->getParam('weightValue'));
  8. }

This will output the three items Code, Zend Framework and PHP with the absolute values 10, 1 and 2.


Zend_Tag