PHPackages                             kittencup/kp-tree - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. kittencup/kp-tree

ActiveLibrary[Database &amp; ORM](/categories/database)

kittencup/kp-tree
=================

KpTree是一个基于Zend Framweork 2的模块，实现MYSQL树的几个TableGateway

1761PHP

Since Feb 10Pushed 11y agoCompare

[ Source](https://github.com/kittencup/KpTree)[ Packagist](https://packagist.org/packages/kittencup/kp-tree)[ RSS](/packages/kittencup-kp-tree/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

1.概述
----

[](#1概述)

KpTree是一个基于Zend Framweork 2模块,实现MYSQL树形的几个TableGateway

2.安装
----

[](#2安装)

[github下载](https://github.com/kittencup/KpTree.git) 或者 `composer require "kittencup/kp-tree": "dev-master"`

```
#application.config.php
return [
	'modules' => [
        // ...
        'KpTree',
    ],
];

```

3.设置
----

[](#3设置)

1.嵌套集(NestedTable)

数据库参考KpTree/data/nested

```
namespace KpTest\Model\TestTable;
use KpTree\Model\NestedTable;
class TestTable extends NestedTable{
    // 设置数据库名
    protected $table = 'nested';
    // 设定左 字段
    protected $lColumn = 'l';
    // 设定右字段
    protected $rColumn = 'r';
    // 设定深度字段
    protected $depthColumn = 'depth';
}

```

2.路径枚举(PathEnumTable)

数据库参考KpTree/data/pathEnum

```
namespace KpTest\Model\TestTable;
use KpTree\Model\PathEnumTable;
class TestTable extends PathEnumTable{
    // 数据库名
    protected $table = 'pathEnum';
    // 设定路径字段
    protected $pathColumn = 'path';
    // 设定路径分隔符
    protected $pathDelimiter = '/';
    // 设定深度字段
    protected $depthColumn = 'depth';
}

```

3.闭包表(ClosureTable)

数据库参考KpTree/data/closure

```
namespace KpTest\Model\TestTable;
use KpTree\Model\ClosureTable;
class TestTable extends ClosureTable{
    // 数据库表名
    protected $table = 'closure';
    // 存储引用关系的表名
    protected $pathsTable = 'closurePaths';
    // $pathsTable表内 祖先字段名
    protected $ancestorColumn = 'ancestor';
    // $pathsTable表内 后辈字段名
    protected $descendantColumn = 'descendant';
    // $table内 深度字段
    protected $depthColumn = 'depth';
}

```

4.使用
----

[](#4使用)

具体可参考 KpTree\\Model\\TreeTableInterface

添加一个节点

```
$table->addNode(['name'=>'kittencup'],4);

```

移动节点

```
 $table->moveNode(2, 3)

```

根据节点id获取父节点

```
$table->getParentNodeById(12);
$table->getParentNodeById(12,2)
$table->getParentNodeById(12,2,'ASC')
$table->getParentNodeById(12,2,'ASC',['id','name'])

```

根据节点id获取子节点

```
$table->getChildNodeById(12);
$table->getChildNodeById(12,2)
$table->getChildNodeById(12,2,'ASC')
$table->getChildNodeById(12,2,'ASC',['id','name'])

```

根据节点id 删除所有子元素

```
$table->deleteChildNodeById(1);
$table->deleteChildNodeById(1,false);

```

根据节点id 删除节点

```
$table->deleteNodeById(1);

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e59a0a21e90f1d6016e9afc35b5a58d00e34a096cc9c36e896aef5fa20245859?d=identicon)[h112367](/maintainers/h112367)

---

Top Contributors

[![kittencup](https://avatars.githubusercontent.com/u/2220385?v=4)](https://github.com/kittencup "kittencup (7 commits)")

### Embed Badge

![Health badge](/badges/kittencup-kp-tree/health.svg)

```
[![Health](https://phpackages.com/badges/kittencup-kp-tree/health.svg)](https://phpackages.com/packages/kittencup-kp-tree)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
