PHPackages                             rkit/tags-behavior-yii2 - 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. rkit/tags-behavior-yii2

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

rkit/tags-behavior-yii2
=======================

Tags Behavior for Yii2

1.0.0(7y ago)06MITPHP

Since Jul 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/rkit/tags-behavior-yii2)[ Packagist](https://packagist.org/packages/rkit/tags-behavior-yii2)[ Docs](https://github.com/rkit/tags-behavior-yii2)[ RSS](/packages/rkit-tags-behavior-yii2/feed)WikiDiscussions master Synced 2w ago

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

Tags Behavior for Yii2
======================

[](#tags-behavior-for-yii2)

[![Build Status](https://camo.githubusercontent.com/4eeaf83a940354ec29d6a294d7d53c2655e9665580595352302f657a5e24082b/68747470733a2f2f7472617669732d63692e6f72672f726b69742f746167732d6265686176696f722d796969322e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rkit/tags-behavior-yii2)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a565acfaf49e50189bcdc5ba48355e926f86eb6be445444be6811995bdde019a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726b69742f746167732d6265686176696f722d796969322f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/rkit/tags-behavior-yii2/?branch=master)

Flexible yii2 behavior for tags.

Requirements
------------

[](#requirements)

PHP 7

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

[](#installation)

```
composer require rkit/tags-behavior-yii2

```

Configuration
-------------

[](#configuration)

For example, we have a `Post` model and we want to add tags.
Let's do it.

1. Add `tag` and `post_to_tag` tables and a `Tag` model for the tags

```
$this->createTable('{{%tag}}', [
    'id' => $this->primaryKey(),
    'name' => $this->string()->notNull()->unique(),
    'frequency' => $this->integer()->notNull()->defaultValue(0),
]);

$this->createTable('{{%post_to_tag}}', [
    'post_id' => $this->integer()->notNull()->defaultValue(0),
    'tag_id' => $this->integer()->notNull()->defaultValue(0),
]);

$this->addPrimaryKey('', '{{%post_to_tag}}', ['post_id', 'tag_id']);
```

2. Add a `TagsBehavior` behavior to the `Post` model

```
public function behaviors()
{
    return [
        'tagsBehavior' => [
            'class' => 'rkit\tags\behavior\TagsBehavior',
            'relation' => 'tags',
            'tagAttribute' => 'name',
            'tagFrequencyAttribute' => 'frequency', // or false
            'findTag' => function ($value) {
                return Tag::find()->where([$this->tagAttribute => $value])->one();
            },
            'createTag' => function ($value) {
                $tag = new Tag();
                $tag->{$this->tagAttribute} = $value;
                return $tag;
            },
        ],
    ];
}
```

3. Add a `tags` relation (see `relation` option in the behavior)

```
/**
 * @return \yii\db\ActiveQuery
 */
public function getTags()
{
    return $this
        ->hasMany(Tag::class, ['id' => 'tag_id'])
        ->viaTable('{{%post_to_tag}}', ['post_id' => 'id']);
}
```

Usage
-----

[](#usage)

### Add tags

[](#add-tags)

```
$model = new Post();
$model->setTagValues(['example1', 'example2']);
$model->save();
```

### Get tags

[](#get-tags)

```
$post = Post::find()->with('tags')->where(['id' => $id])->one();
$post->getTagValues();
```

### Remove tags

[](#remove-tags)

```
$model = new Post();
$model->setTagValues([]);
$model->save();
```

Tests
-----

[](#tests)

- [See docs](/tests/#tests)

Coding Standard
---------------

[](#coding-standard)

- PHP Code Sniffer ([phpcs.xml](./phpcs.xml))

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2906d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/26f3097962081483e807941af9e4836adfe28c8c964b3972514e04deeeb10ed6?d=identicon)[rkit](/maintainers/rkit)

---

Top Contributors

[![rkit](https://avatars.githubusercontent.com/u/4242765?v=4)](https://github.com/rkit "rkit (10 commits)")

---

Tags

tagsyii2yii2extensionBehaviortags

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/rkit-tags-behavior-yii2/health.svg)

```
[![Health](https://phpackages.com/badges/rkit-tags-behavior-yii2/health.svg)](https://phpackages.com/packages/rkit-tags-behavior-yii2)
```

###  Alternatives

[sjaakp/yii2-taggable

Manage tags of ActiveRecord in Yii2.

2931.8k](/packages/sjaakp-yii2-taggable)[mdmsoft/yii2-autonumber

Auto number extension for the Yii framework

1831.2k](/packages/mdmsoft-yii2-autonumber)[valentinek/yii2-closure-table-behavior

This extension allows you to get functional for closure table trees.

1615.4k](/packages/valentinek-yii2-closure-table-behavior)[v0lume/yii2-meta-tags

DB based model meta data for SEO

194.1k](/packages/v0lume-yii2-meta-tags)

PHPackages © 2026

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