mhndev/yii2-taxonomy-term
Composer 安装命令:
composer require mhndev/yii2-taxonomy-term
包简介
taxonomy term implementation in Yii2
README 文档
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();
统计信息
- 总下载量: 1.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-30