PHPackages                             rde/menutree - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. rde/menutree

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rde/menutree
============

選單樹

0.2.13(10y ago)012MITPHPPHP &gt;=5.3.0

Since Jan 14Pushed 9y ago1 watchersCompare

[ Source](https://github.com/syhlion/menutree)[ Packagist](https://packagist.org/packages/rde/menutree)[ RSS](/packages/rde-menutree/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (17)Used By (0)

MenuTree
========

[](#menutree)

[![Build Status](https://camo.githubusercontent.com/d60c8bc3035ff55f4bcfc97028b9e106d28e60e26947e31c4d69ac5329f4d384/68747470733a2f2f7472617669732d63692e6f72672f7379686c696f6e2f6d656e75747265652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/syhlion/menutree)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c489e1087e741f50b086e1cfec29ef4c8f4a0fed92f73cf6df21dd1d166b9438/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7379686c696f6e2f6d656e75747265652f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/syhlion/menutree/)[![SensioLabsInsight](https://camo.githubusercontent.com/857d4f60dbb3d7b71060d72f9d3882cd1b205ec230abe39c2ac347d08d338b05/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f61326334343830342d386237352d343039652d383333382d3238313761623034343530372f6d696e692e706e67)](https://insight.sensiolabs.com/projects/a2c44804-8b75-409e-8338-2817ab044507)

Installation：
-------------

[](#installation)

```
{
    "require": {
        "rde/menutree": "0.2.*@dev"
    }
}
```

- PHP環境需要pdo\_sqlite pdo\_mysql (預設載體)
- 把db\_schema資料夾裡的sql 部屬在database。
- 預設資料載體sqlite (/src/storage/menudata.slite3) 裡面的資料格式 （id, item\_id, parent\_id, depth, left, right, url\_name, url），其中item\_id為不可重複的唯一key，可用字串，如不小心寫入重複key，在MenuData取資料時也會慮掉重複字串。id為一般流水號，其他欄位可填可不填。
- 唯一要注意，如果此比資料為樹狀資料最上層，其parnet\_id 要填入字串'null'
- 也可各自實現IMenuProvider &amp; IUserProvider 來使用自己儲存體

Usage：
------

[](#usage)

```
/*
假設原始資料為:
array(
    array(
    "id" => 1,
    "item_id" => key_1,
    "parent_id" => 'null'
    "depth" => 0,
    "left" => 1,
    "right" => 2,
    "url_name" => test1,
    "url" => contorller1/method1
    ),
    array(
    "id" => 2,
    "item_id" => key_2,
    "parent_id" => key_1,
    "depth" => 1,
    "left" => 3,
    "right" => 4,
    "url_name" => test2,
    "url" => contorller2/method2
    ),
);
*/

//可自行實作使用者選單，只要最後給MenuData的過濾資料格式如下面範例即可
$pdo_mysql = new PDO('mysql:host=127.0.0.1;dbname=account','root','xxxx');
$user = new User($pdo_mysql);

//find_menu() 會用array回傳 每個item_id  ex array(key_1,key_2...)
//建構參數pdo 可選填，沒填預設會讀取src/storage/menudata.sqlite3 裡的資料
$menuOrigin = new MenuData();

$insertData = array(
    array(
        "id" => 1,
        "item_id" => key_3,
        "parent_id" => 'key_1'
        "depth" => 0,
        "left" => 1,
        "right" => 2,
        "url_name" => test3,
        "url" => contorller3/method3
        ),
);
/*
結果為
array(
    array(
    "id" => 1,
    "item_id" => key_1,
    "parent_id" => 'null'
    "depth" => 0,
    "left" => 1,
    "right" => 2,
    "url_name" => test1,
    "url" => contorller1/method1
    ),
    array(
    "id" => 1,
    "item_id" => key_3,
    "parent_id" => 'key_1'
    "depth" => 0,
    "left" => 1,
    "right" => 2,
    "url_name" => test3,
    "url" => contorller3/method3
    ),
    array(
    "id" => 2,
    "item_id" => key_2,
    "parent_id" => key_1,
    "depth" => 1,
    "left" => 3,
    "right" => 4,
    "url_name" => test2,
    "url" => contorller2/method2
    ),
);
*/
$menuOrigin->setFilter($user->find_menu())->insert(1, $insertData)->get();

//建構選單樹狀物件
$menutree = new MenuTree($menuOrigin);

//可拿到完整的樹狀結構
$tree = $menutree->get();
/*
最後get回來的資料格式如以下:
array(
    array(
        "deep" => 0,
        "self" => array(
            "id" => 1,
            "item_id" => key_1,
            "parent_id" => 'null'
            "depth" => 0,
            "left" => 1,
            "right" => 2,
            "url_name" => test1,
            "url" => contorller1/method1
        ),
        "children" => array(
            array(
                "deep" => 2,
                "self" => array(
                    "id" => 2,
                    "item_id" => key_2,
                    "parent_id" => key_1,
                    "depth" => 1,
                    "left" => 3,
                    "right" => 4,
                    "url_name" => test2,
                    "url" => contorller2/method2
                ),
                "children" => array(),
            )
        )

    )
)
*/
$bool = $menutree->check("controller/method"); //可判斷此uri是否符合權限 會回傳 true false
```

License
-------

[](#license)

Composer is licensed under the MIT License - see the LICENSE file for details

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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.

###  Release Activity

Cadence

Every ~11 days

Recently: every ~0 days

Total

14

Last Release

4002d ago

PHP version history (2 changes)0.2.0PHP &gt;=5.4.0

0.2.7PHP &gt;=5.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ce13795e531e023fa7aa838d3cb112e0c22050bfa6695b317435e30479a4423?d=identicon)[syhlion](/maintainers/syhlion)

---

Top Contributors

[![syhlion](https://avatars.githubusercontent.com/u/8326955?v=4)](https://github.com/syhlion "syhlion (44 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rde-menutree/health.svg)

```
[![Health](https://phpackages.com/badges/rde-menutree/health.svg)](https://phpackages.com/packages/rde-menutree)
```

###  Alternatives

[phonetworks/pho-lib-graph

A general purpose graph library in PHP

556.0k1](/packages/phonetworks-pho-lib-graph)[pxlrbt/php-scoper-prefix-remover

101.6k](/packages/pxlrbt-php-scoper-prefix-remover)

PHPackages © 2026

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