PHPackages                             justinvoelker/yii2-tagging - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. justinvoelker/yii2-tagging

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

justinvoelker/yii2-tagging
==========================

Turn delimited data into tags

1.0.2(10y ago)84.5k↓66.7%6[1 issues](https://github.com/justinvoelker/yii2-tagging/issues)1BSD-3-ClausePHP

Since Feb 11Pushed 10y ago4 watchersCompare

[ Source](https://github.com/justinvoelker/yii2-tagging)[ Packagist](https://packagist.org/packages/justinvoelker/yii2-tagging)[ RSS](/packages/justinvoelker-yii2-tagging/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (4)Used By (1)

\#Tagging for Yii2

Turn delimited data into tags

There are multiple extensions for brining tagging functionality into Yii but **Tagging** aims to be the simplest. Built for Yii2, **Tagging** does not use additional tables, models, or relationships to store or manage tags or how often they appear. Instead, it works with an existing field of your choosing and turns its contents into tags.

We'll use the following `posts` table as an example.

   id post\_title post\_body tags     1 My first post! body of new blog welcome   2 Why Tagging is great some more content yii2-tagging,tutorial   3 Advanced Tagging tips most recent post yii2-tagging,tutorial,advanced  Tagging includes two classes: *TaggingQuery* and *TaggingWidget*. *TaggingQuery* returns a php array which can be used in form's select field or as input to *TaggingWidget* which can display the tags as a list or tag cloud.

Keep in mind that your tags don't need to be comma-delimited. You can use practically any delimiter you like!

\##Installation

\###Install the extension

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist justinvoelker/yii2-tagging "*"

```

or add

```
"justinvoelker/yii2-tagging": "*"

```

to the require section of your `composer.json` file.

### Styles

[](#styles)

Follow one of the directions below to use the styles necessary for the tag\_cloud

#### Option 1: Manually combine stylesheets

[](#option-1-manually-combine-stylesheets)

Open your the `vendors\justinvoelker\yii2-tagging\css` directory and add the styles found in `tagging.css` to your own stylesheet.

#### Option 2: Include the delivered asset bundle

[](#option-2-include-the-delivered-asset-bundle)

Add `justinvoelker\tagging\TaggingAsset` as a dependency in your `assets\AppAsset` file. It should look similar to the following:

```
...
public $depends = [
    'yii\web\YiiAsset',
    'yii\bootstrap\BootstrapAsset',
    'justinvoelker\tagging\TaggingAsset',
];
...

```

\##Usage

\###TaggingQuery

To create a php array of key=&gt;value pairs (where key is the tag and value is the frequency of that tag), use TaggingQuery:

```
$query = new TaggingQuery;
$tags = $query
    ->select('tags')
    ->from('posts')
    ->getTags();
```

\###TaggingWidget

To create a tag cloud or list, use TaggingWidget:

```
echo TaggingWidget::widget([
    'items' => $tags,
]);
```

\###TaggingQuery and TaggingWidget

If necessary, you can combine the two. If you have multiple widgets on the same page that will use roughly the same set of data, simple pass the results of an initial *TaggingQuery* into another *TaggingQuery* for further limiting or ordering as follows:

```
$query = new TaggingQuery;

$tagsA = $query
    ->select('tags')
    ->from('posts')
    ->displaySort(['name' => SORT_ASC])
    ->getTags();
echo TaggingWidget::widget([
    'items' => $tagsA,
    'format' => 'cloud',

$tagsB = $query
    ->items($tagsA)
    ->displaySort(['freq' => SORT_DESC])
    ->getTags();
echo TaggingWidget::widget([
    'items' => $tagsB,
    'format' => 'list',
]);
```

The above example will only use one database query but will display two TaggingWidgets. The first will be a tag cloud of tags sorted by name whereas the second will be an unordered list (ul) sorted from most to least frequent.

\##Available Options

Many options are available for selecting and formatting the data and results. The following examples show which options are available. Exploring the code will give further descriptions of each option.

\###TaggingQuery

Only `select` and `from` or an array of `items` are required. If all three are specified, the `items` values will be used. Note that `exclude` and `includeOnly` would likely not be used at the same time which is why `includeOnly` is commented out in the examples below. Also commented out for this example is `items`.

Since *TaggingQuery* extends `yii\db\Query` you can use any other properties available to that class as well. While using `where` may come in handy, be careful not to use properties such as `distinct` which could have unintended consequences.

The following *TaggingQuery* would result in an array of the 50 most frequent comma-separated tags from the post table, except for the 'junk' tag, displayed alphabetically.

```
$query = new TaggingQuery;
$tags = $query
    // used to refine an existing list
    //->items($existingTaggingQueryResults)
    // field that contains the desired tags
    ->select('tags')
    // table to select from
    ->from('post')
    // delimiter (default: `,` (comma))
    ->delimiter(',')
    // number of tags to display (omit for all tags)
    ->limit(50)
    // order used when a limit is being applied
    ->limitSort(['freq' => SORT_DESC, 'name' => SORT_ASC])
    // order of the resulting list
    ->displaysort(['name' => SORT_ASC])
    // array of tags to be excluded
    ->exclude(['junk'])
    // array of tags to be included (all other omitted)
    //->includeOnly(['feature', 'special'])
    // return the array of tag=>frequency pairs
    ->getTags();
```

\###TaggingWidget

Only `items` is required.

All of the selecting, limiting, sorting, and excluding/including of tags is performed by *TaggingQuery*. Once a list of items is returned from *TaggingQuery*, it may be passed into a *TaggingWidget* for display.

Continuing with the previous example, the following *TaggingWidget* would result in the previously selected tags being displayed in a tag cloud whose text will be justified, with tags ranging in size from 14-22px, and linking to pages in the format of `/index.php?r=post/index&tag=TAGNAME`

```
echo TaggingWidget::widget([
    // TaggingQuery results
    'items' => $tags,
    // smallest tag size (default: 14)
    'smallest' => '14',
    // largest tag size (default: 22)
    'largest' => '22',
    // unit for tag sizes (default: px)
    'unit' => 'px',
    // display format of 'cloud', 'ul', or 'ol' (default: cloud)
    'format' => 'cloud',
    // url for links (omit for no link)
    'url' => ['post/index'],
    // parameter to be appended to url with tag
    'urlParam' => 'tag',
    // options applied to the list
    'ulOptions' => ['style' => 'text-align:justify'],
    // options applied to the list item
    'liOptions' => [],
    // options applied to the link (if present)
    'linkOptions' => [],
]);
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~87 days

Total

3

Last Release

3935d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/250c304267e68b69e45180f9863c1ff7578780afae46e118be7b3ff71de72a9b?d=identicon)[justinvoelker](/maintainers/justinvoelker)

---

Top Contributors

[![justinvoelker](https://avatars.githubusercontent.com/u/2441889?v=4)](https://github.com/justinvoelker "justinvoelker (5 commits)")[![shi-yang](https://avatars.githubusercontent.com/u/5102567?v=4)](https://github.com/shi-yang "shi-yang (2 commits)")

---

Tags

yii2tag

### Embed Badge

![Health badge](/badges/justinvoelker-yii2-tagging/health.svg)

```
[![Health](https://phpackages.com/badges/justinvoelker-yii2-tagging/health.svg)](https://phpackages.com/packages/justinvoelker-yii2-tagging)
```

###  Alternatives

[sjaakp/yii2-taggable

Manage tags of ActiveRecord in Yii2.

3030.6k](/packages/sjaakp-yii2-taggable)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
