tenga007 / yii2-closure-table-behavior
本扩展允许您获取用于闭包表树的函数。
0.8.0
2015-01-24 08:48 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-20 19:19:49 UTC
README
这是yii-closure-table-behavior的Yii2端口。扩展允许通过闭包表方法管理数据库中存储的树。
安装
安装此扩展的首选方式是通过composer。
运行以下命令之一:
php composer.phar require valentinek/yii2-closure-table-behavior "*"
或者
"valentinek/yii2-closure-table-behavior": "*"
将以下内容添加到您的composer.json文件的require部分。
配置
首先,您需要按照以下方式配置模型
class Category extends ActiveRecord { public $leaf; public function behaviors() { return [ [ 'class' => ClosureTable::className(), 'tableName' => 'category_tree' ], ]; } public static function find() { return new CategoryQuery(static::className()); } }
其次,您需要按照以下方式配置查询模型
class CategoryQuery extends ActiveQuery { public function behaviors() { return [ [ 'class' => ClosureTableQuery::className(), 'tableName' => 'category_tree' ], ]; } }
迁移/更改数据库架构
配置模型后,您必须将迁移文件从行为迁移文件夹复制到您的项目迁移文件夹。请阅读文件中的注释,根据需要更改迁移并运行迁移。
php yii migrate
您还可以直接使用schema文件夹中.sql转储文件中的示例更改数据库架构。
路线图
1. Write documentation
2. Write tests
3. bug fixes
4. EVENT_DELETE
5. DeleteNode method refactoring
6. isAncestor() and isDescendant() methods