PHPackages                             sjaakp/yii2-taggable - 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. sjaakp/yii2-taggable

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

sjaakp/yii2-taggable
====================

Manage tags of ActiveRecord in Yii2.

2.0.2(6y ago)3030.6k↓46.8%17[3 PRs](https://github.com/sjaakp/yii2-taggable/pulls)MITPHP

Since Jun 22Pushed 6y ago4 watchersCompare

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

READMEChangelog (7)Dependencies (2)Versions (8)Used By (0)

yii2-taggable
=============

[](#yii2-taggable)

#### Manage tags of ActiveRecords in PHP-framework Yii 2.0

[](#manage-tags-of-activerecords-in-php-framework-yii-20)

[![Latest Stable Version](https://camo.githubusercontent.com/0cc69bdb35ab35a10d161347dfd383cd33efc6b13c4cb9a28155dad9118de179/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d7461676761626c652f762f737461626c65)](https://packagist.org/packages/sjaakp/yii2-taggable)[![Total Downloads](https://camo.githubusercontent.com/84059b737b9381205bdf528ad641bc5d617a29e23daef554a389c1550fc269a2/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d7461676761626c652f646f776e6c6f616473)](https://packagist.org/packages/sjaakp/yii2-taggable)[![License](https://camo.githubusercontent.com/469477e8faec1a82ed2c205b8e34cbd1dcc87902b8b11e554d1f430255ac4cde/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d7461676761626c652f6c6963656e7365)](https://packagist.org/packages/sjaakp/yii2-taggable)

This package contains five classes to handle the tagging of ActiveRecords with keywords or similar. The tags can be associated with or decoupled from a model (ActiveRecord), and can be sorted. Tags are manipulated with the excellent [jQuery tagEditor developed by Pixabay](http://goodies.pixabay.com/jquery/tag-editor/demo.html).

The four main classes of **yii2-taggable** are:

- **TagBehavior** - makes an ActiveRecord behave like a tag;
- **TaggableBehavior** - adds the handling of tags to an ActiveRecord;
- **TagEditor** - widget to manipulate tags;
- **TagSuggestAction** - feeds the autocomplete function of TagEditor with data.

There is also a class **TagEditorAsset**, which is a helper class for TagEditor.

A demonstration of the **yii2-taggable** suit is [here](https://sjaakpriester.nl/software/taggable).

Notice that the API for version 2 is slightly different from that of version 1.

Installation
------------

[](#installation)

The preferred way to install **yii2-taggable** is through [Composer](https://getcomposer.org/). Either add the following to the require section of your `composer.json` file:

`"sjaakp/yii2-taggable": "*"`

Or run:

`composer require sjaakp/yii2-taggable "*"`

You can manually install **yii2-taggable** by [downloading the source in ZIP-format](https://github.com/sjaakp/yii2-taggable/archive/master.zip).

Setup
-----

[](#setup)

Suppose we have a class (ActiveRecord) `Article` of articles which can be tagged, and another class `Tag` to hold the tags.

Tag has at least the following attributes:

- `id`: primary key;
- `name`: to hold the actual tag keyword;

### Junction table

[](#junction-table)

`Article` and `Tag` are linked with a junction table in a many-to-many relation. Let's call the table `article_tag`. It has the following fields:

- `model_id`: holds the primary key value of an `Article`;
- `tag_id`: holds the primary key value of a `Tag`;
- `ord`: holds the sorting order of a `Tag`.

The junction table doesn't need to have a primary key. It's a good idea to set indexes on both `model_id` and `tag_id`.

### TaggableBehavior

[](#taggablebehavior)

The class `Article` is *taggable*, and should be set up like this:

```

	...

	...

```

`tags` is also a new virtual attribute of `Article`, added to it by **TaggableBehavior**. `'tag/suggest'` is the base of the route to the `suggest` action in `TagController`, which we defined before. Learn more about the `clientOptions` from [Pixabay](https://goodies.pixabay.com/jquery/tag-editor/demo.html).

Modifications
-------------

[](#modifications)

The basic setup of **yii2-taggable** can be modified in a number of ways. Refer to the source files to see which other options are available. Some are:

- **nameAttribute**: name attribute of the tag class. Defined in TagBehavior, TaggableBehavior, and TagSuggestAction. Default: `'name'`.
- **tagKeyColumn** and **modelKeyColumn**: foreign key fields in the junction table. Defined in TagBehavior and TaggableBehavior. Defaults: `'tag_id'` and `'model_id'` respectively.
- **orderColumn**: holds order information in the junction table. Defined in TaggableBehavior.
- **renderLink**: callable, `function($tag, $options)`, returning the HTML code for a single tag link. Defined by TagBehavior. If not set (default), TagBehaviour renders tag link as a simple HTML a.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 86.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 ~274 days

Recently: every ~382 days

Total

7

Last Release

2339d ago

Major Versions

1.0.3 → 2.0.02019-12-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/156f636aceedc73021a2bfafb5433271c2c55d6cf4bce06b12902c85b4b491f1?d=identicon)[sjaakp](/maintainers/sjaakp)

---

Top Contributors

[![sjaakp](https://avatars.githubusercontent.com/u/5585878?v=4)](https://github.com/sjaakp "sjaakp (19 commits)")[![drsdre](https://avatars.githubusercontent.com/u/809827?v=4)](https://github.com/drsdre "drsdre (2 commits)")[![mike-kramer](https://avatars.githubusercontent.com/u/9973256?v=4)](https://github.com/mike-kramer "mike-kramer (1 commits)")

---

Tags

yii2extensionBehaviorwidgetyiitagstag

### Embed Badge

![Health badge](/badges/sjaakp-yii2-taggable/health.svg)

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

PHPackages © 2026

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