yii2-tagging Turn delimited data into tags

  1. Installation
  2. Usage
  3. Further information

Tagging was created for a my personal use but perhaps others can benefit from its simplicity as well. Getting tired of the typical tagging systems that required other tables to store tags and lots of logic to keep them in sync, I set out to create an extension that had absolutely no reliance on other tables/models/relationships. Simply get the tags from all appropriate records at the time they are needed. No "tag" tables, no counts of tag usages or models to update tags, just a field that contains the tags for a given record. This is where Tagging comes in. Github has more examples and documentation but here is a quick rundown of functionality.


Add the following to the require section of your composer.json file.

"justinvoelker/yii2-tagging": "*"

You will also need some styles for the tag_cloud which can either be used by copying them from the included css file or by adding justinvoelker\tagging\TaggingAsset as a dependency in your assets\AppAsset file. See Github for a more detailed explanation.


The following only briefly explains the possibilities of this extension. The options shown are the bare minimum required for usage while many more options exist for changing how tags are retrieved, which tags are included, how they are sorted, and adjusting display.

Don't forget to add use justinvoelker\tagging\TaggingQuery; and/or use justinvoelker\tagging\TaggingWidget; to any pages where you want to use TaggingQuery or TaggingWidget.


To create a php array of key=>value pairs (where key is the tag and value is the frequency of that tag), use TaggingQuery. The resulting values can either be used to create a TaggingWidget or as the options in select field on a form. Options exist to limit the final list of tags as well as affect the order in which they appear.

$query = new TaggingQuery;
$tags = $query

To create a tag cloud or list, use TaggingWidget. By passing in a list of values from a TaggingQuery, the values can be display as a list or a tag cloud. Options exist to affect the appearance such as size, links, and list attributes.

echo TaggingWidget::widget([
    'items' => $tags,

Further information

The GitHub README will contain the full documentation for this extension and will be updated as necessary. This extension page merely serves as a quick reference and pointer to the GitHub information.

Please do not ask for help in the comments below. If you require assistance please seek answers in the forum or GitHub for this extension.

0 0
1 follower
Yii Version: 2.0
License: BSD-2-Clause
Category: User Interface
Developed by: justinvoelker
Created on: Feb 11, 2015
Last updated: 9 years ago

Related Extensions