Git Product home page Git Product logo

yii2-taxonomy-term's Introduction

Taxonomy Term

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();

yii2-taxonomy-term's People

Contributors

mhndev avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

marty-macfly

yii2-taxonomy-term's Issues

Behavior, Tag and Property

Hi guy,

First for this module it was part of what i was looking for :) I made some work around this modul to make it suits my need so perhaps you want to have a look, it's here https://github.com/Marty-Macfly/yii2-taxonomy/

I was looking for a taxonomy module to add taxonomy to any model of my app and i do not what to have many tables for every model, so your module was perfect for that need. Thanks for that.

I was not really found of the usage of trait to extend a model, so i've implemented behavior (i think they do quite the same has you trait).

Also i've extend some of your model to add some small features. I think the most interesting one is on the Term model to add the increase and decrease of usage counter in it (instead of in the trait).

If you want i can make pull request just let me know if your are interested by some of them. And thanks again for your work.

Cheers,
Macfly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.