mhndev/yii2-taxonomy-term

taxonomy term implementation in Yii2

Installs: 1 722

Dependents: 1

Suggesters: 0

Security: 0

Stars: 4

Watchers: 3

Forks: 1

Open Issues: 1

Type:yii2-extension

1.0.5 2016-08-31 11:02 UTC

This package is auto-updated.

Last update: 2024-04-06 08:17:58 UTC


README

taxonomy term implementation in Yii2

Installation

The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist mhndev/yii2-taxonomy-term "1.*"

or add

"mhndev/yii2-taxonomy-term": "1.*"

to the require section of your composer.json file.

Execute Migrations

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

Usage

user mhndev\yii2TaxonomyTerm\traits\TermableTrait in each Model which you want to use taxonomy-term for

example

Post Model
class Post extends ActiveRecord
{

    use TermableTrait;

    /**
     * @return string
     */
    public static function tableName()
    {
        return 'posts';

    }

    /**
     * @return array
     */
    public function rules()
    {
        return [
            [['title'], 'required'],
            [['text'], 'required'],
        ];
    }

}

attach a term to an entity

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

detach a term from an entity

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

list terms of an entity

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

get term tree

    $term = Term::findOne(['id'=>1]);
    $term->getTree();