PHPackages                             macfly/yii2-taxonomy - 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. macfly/yii2-taxonomy

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

macfly/yii2-taxonomy
====================

Extend Yii2-taxonomy-term (by mhndev) by adding term definition (tags, properties). The extension complete the original module by adding behavior to add term, properties and tags to your model.

1.2.0(8y ago)21.6k2BSD-3-ClausePHP

Since Nov 6Pushed 8y ago1 watchersCompare

[ Source](https://github.com/marty-macfly/yii2-taxonomy)[ Packagist](https://packagist.org/packages/macfly/yii2-taxonomy)[ RSS](/packages/macfly-yii2-taxonomy/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

yii2-taxonomy
=============

[](#yii2-taxonomy)

Yii2 Taxonomy management. A component which adds generic taxonomy functionalities to your application. The component comes with a couple of term definitions(tags, properties). Those definitions can be enable on any models by adding the chossen behavior. This extension depends of [yii2-taxonomy-term](https://github.com/mhndev/yii2-taxonomy-term) (by [mhndev](https://github.com/mhndev)).

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist macfly/yii2-taxonomy "*"

```

or add

```
"macfly/yii2-taxonomy": "*"

```

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

Migration
---------

[](#migration)

```
php yii migrate --migrationPath=@vendor/mhndev/yii2-taxonomy-term/src/migrations

```

Usage
-----

[](#usage)

Configuring to manage Taxonomy and Term in web interface
--------------------------------------------------------

[](#configuring-to-manage-taxonomy-and-term-in-web-interface)

Configure **config/web.php** as follows

```
'modules' => [
    ................
    'taxonomy' => [
        'class' => 'macfly\taxonomy\Module'
    ],
    ................
],
```

- Pretty Url's /taxonomy
- No pretty Url's index.php?r=taxonomy

Configuring to use Term
-----------------------

[](#configuring-to-use-term)

Configure model as follows

```
use macfly\taxonomy\behaviors\BaseTermBehavior;

/**
 * ...
 * @property array $terms
 */
class Post extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
            BaseTermBehavior::className(),
            ...
            ],
        ];
    }

}
```

### get terms of an entity

[](#get-terms-of-an-entity)

```
$post = Post::findOne(['id'=>1]);
$post->terms;
```

### set terms of an entity (will remove all other term)

[](#set-terms-of-an-entity-will-remove-all-other-term)

```
$post = Post::findOne(['id'=>1]);
$terms = [
        Term::findOne(1),
        Term::findOne(12),
        ];
$post->terms = $terms;
```

### detach a term from an entity

[](#detach-a-term-from-an-entity)

```
$term = Term::findOne(['id'=>1]);
$post = Post::findOne(['id'=>1]);
$post->delTerm($term);
```

### check if term exist on entity

[](#check-if-term-exist-on-entity)

```
$term = Term::findOne(['id'=>1]);
$post = Post::findOne(['id'=>1]);
$post->hasTerm($term);
```

### add term to an entity (will keep others term)

[](#add-term-to-an-entity-will-keep-others-term)

```
$term = Term::findOne(['id'=>1]);
$post = Post::findOne(['id'=>1]);
$post->addTerm($term);
```

Configuring to use Property and Term
------------------------------------

[](#configuring-to-use-property-and-term)

Properties are taxonomy of defined 'type' and they have name and value. You can add multiple properties to an item. And a property can have multiple 'name' and values to an item.

Configure model as follows

```
use macfly\taxonomy\behaviors\PropertyTermBehavior;

/**
 * ...
 * @property array $terms
 * @property array $envs
 */
class Post extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
                PropertyTermBehavior::className(),
                ...
            ],
        ];
    }

    # Define the get method of property 'env'
    public function getEnvs()
    {
        return $this->getPropertyTerms('env');
    }

    # Define the set method of property 'env'
    public function setEnvs($terms)
    {
        return $this->setPropertyTerms('env', $terms);
    }

    # Add term by name and value
    public function addEnv($name, $value)
    {
        return $this->addPropertyTerm('env', $name, $value);
    }

    # Detach term by name and value
    public function delEnv($name, $value)
    {
        return $this->delPropertyTerm('env', $name, $value);
    }

    # Has term by name and value
    public function hasEnv($name, $value)
    {
        return $this->hasPropertyTerm('env', $name, $value);
    }
}
```

### get terms for property 'env' of an entity

[](#get-terms-for-property-env-of-an-entity)

```
$post = Post::findOne(['id'=>1]);
$post->envs;
```

### set terms for property 'env' of an entity (will remove all other term for property 'env')

[](#set-terms-for-property-env-of-an-entity-will-remove-all-other-term-for-property-env)

```
$post = Post::findOne(['id'=>1]);
$terms = [
    Term::findOne(1),
    Term::findOne(12),
  ];
$post->envs = $terms;
```

### detach property 'env' by is name and value from an entity (if you want to detach it by term, just use delTerm($term))

[](#detach-property-env-by-is-name-and-value-from-an-entity-if-you-want-to-detach-it-by-term-just-use-deltermterm)

```
$post = Post::findOne(['id'=>1]);
$post->delEnv('PWD', '/home/test/');
```

### check if property 'env' exist by name and value on entity (if you want to check it by term, just use hasTerm($term))

[](#check-if-property-env-exist-by-name-and-value-on-entity-if-you-want-to-check-it-by-term-just-use-hastermterm)

```
$post = Post::findOne(['id'=>1]);
$post->hasEnv('PWD', '/home/test');
```

### add property 'env' by name and value to an entity (will keep others term, if you want to add it by term, just use addTerm($term))

[](#add-property-env-by-name-and-value-to-an-entity-will-keep-others-term-if-you-want-to-add-it-by-term-just-use-addtermterm)

```
$post = Post::findOne(['id'=>1]);
$post->addEnv('PWD', '/home/test');
```

Configuring to use Tags, Property and Term
==========================================

[](#configuring-to-use-tags-property-and-term)

Basically tags represent properties of type 'tag' and name 'name'. You can add multiple tags to an item.

Configure model as follows

```
use macfly\taxonomy\behaviors\TagTermBehavior;

/**
 * ...
 * @property array $terms
 * @property array $tags
 */
class Post extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
                TagTermBehavior::className(),
                ...
            ],
        ];
    }

}
```

You can change 'tag' taxonomy type and name for a specific model with the following :

```
use macfly\taxonomy\behaviors\TagTermBehavior;

/**
 * ...
 * @property array $terms
 * @property array $tags
 */
class Post extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
            'tag' => [
                'class' => TagBehavior::className(),
                     'type' => 'myposttagtype',
                     'name' => 'myposttagname',
            ],
        ];
    }
}
```

get tags of an entity
---------------------

[](#get-tags-of-an-entity)

```
$post = Post::findOne(['id'=>1]);
$post->tags;
```

set tags of an entity (will remove all other term)
--------------------------------------------------

[](#set-tags-of-an-entity-will-remove-all-other-term)

```
$post = Post::findOne(['id'=>1]);
$post->tags = ['tags1', 'tag2', 'test'];
// Or
$post->tags = 'tags1,tag2,test';
```

detach a tag from an entity
---------------------------

[](#detach-a-tag-from-an-entity)

```
$post = Post::findOne(['id'=>1]);
$post->delTag('tags1');
```

check if tag exist on entity
----------------------------

[](#check-if-tag-exist-on-entity)

```
$post = Post::findOne(['id'=>1]);
$post->hasTag('test');
```

add tag to an entity (will keep others tag)
-------------------------------------------

[](#add-tag-to-an-entity-will-keep-others-tag)

```
$post = Post::findOne(['id'=>1]);
$post->addTag('foo');
```

Configuring to purge unused Term
================================

[](#configuring-to-purge-unused-term)

Basically unused Term will be delete in the period of time (default is 30 day) it's help to remove useless tag.

Configure route for action **config/console.php** as follows:

```
'modules' => [
    ................
    'taxonomy' => [
        'class' => 'macfly\taxonomy\Module'
    ],
    ................
],
```

Default term will be delete if *updated\_at* later than one month, if you want to define specific period time, just specify it on command line:

And you can add a cron job () to run at *00:00 on every Sunday* with some controller action like this:

on **Linux:**

```
    0 0 * * 0 /path/to/yii/application/yii taxonomy/term/clear 50 >> /var/log/console-app.log 2>&1
```

on **Window Task Schedule:**

```
    /path/to/yii/application/yii taxonomy/term/clear
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

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

Every ~144 days

Total

3

Last Release

3235d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/74924cc29f67eef7ca7640876dd3462974466ea683f8d059c70a33b3087d7230?d=identicon)[Macfly](/maintainers/Macfly)

---

Top Contributors

[![marty-macfly](https://avatars.githubusercontent.com/u/12715929?v=4)](https://github.com/marty-macfly "marty-macfly (8 commits)")

---

Tags

propertyyii2tagspropertiestaxonomytermmhndev

### Embed Badge

![Health badge](/badges/macfly-yii2-taxonomy/health.svg)

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

###  Alternatives

[creocoder/yii2-taggable

The taggable behavior for the Yii framework

133133.9k9](/packages/creocoder-yii2-taggable)[aliziodev/laravel-taxonomy

Laravel Taxonomy is a flexible and powerful package for managing taxonomies, categories, tags, and hierarchical structures in Laravel applications. Features nested-set support for optimal query performance on hierarchical data structures.

24423.9k](/packages/aliziodev-laravel-taxonomy)[netgen/tagsbundle

Netgen Tags Bundle is an Ibexa DXP bundle for taxonomy management and easier classification of content, providing more functionality for tagging content than ibexa\_keyword field type included in Ibexa core.

48464.0k27](/packages/netgen-tagsbundle)[sjaakp/yii2-taggable

Manage tags of ActiveRecord in Yii2.

2931.8k](/packages/sjaakp-yii2-taggable)

PHPackages © 2026

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