valentinek/yii2-closure-table-behavior

该扩展允许您获取闭包表树的函数。

安装数: 12,854

依赖项: 0

建议者: 0

安全: 0

星标: 16

关注者: 3

分支: 6

类型:yii2-extension

0.8.0 2015-01-24 08:48 UTC

This package is not auto-updated.

Last update: 2024-09-24 01:05:41 UTC


README

这是yii-closure-table-behavior的Yii2端口。扩展允许通过闭包表方法管理存储在数据库中的树。

安装

安装此扩展的首选方式是通过composer

运行以下命令之一:

php composer.phar require valentinek/yii2-closure-table-behavior "*"

或添加以下内容到您的composer.json文件的require部分:

"valentinek/yii2-closure-table-behavior": "*"

配置

首先,您需要按照以下方式配置模型:

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 dump文件示例更改数据库模式。

路线图

1. Write documentation
2. Write tests
3. bug fixes
4. EVENT_DELETE
5. DeleteNode method refactoring
6. isAncestor() and isDescendant() methods