scolib/tree

tree
1,031 2
Install
composer require scolib/tree
Latest Version:v1.0.3
PHP:~5.6|~7.0
License:Apache-2.0
Last Updated:Jan 3, 2018
Links: GitHub  ·  Packagist
Maintainer: klgd

ScoLib/tree

是一个将数据格式化为树形结构的类库

StyleCI Latest Stable Version Total Downloads Latest Unstable Version License

安装

执行命令:

composer require scolib/tree

或 在 composer.json 文件中:

"require": {
    "scolib/tree": "^1.0"
}

并执行 composer update

使用

<?php 
namespace App\Repositories;

use Sco\Tree\Traits\TreeTrait;

class MyClass
{
    use TreeTrait;
    
    // 自定义属性(可选)
    protected $treeNodeIdName = 'id';
    protected $treeNodeParentIdName = 'parent_id';
    protected $treeSpacer = '&nbsp;&nbsp;&nbsp;';
    protected $treeFirstIcon = '&nbsp;&nbsp;&nbsp;│ ';
    protected $treeMiddleIcon = '&nbsp;&nbsp;&nbsp;├─ ';
    protected $treeLastIcon = '&nbsp;&nbsp;&nbsp;└─ ';
    
    /**
     * 获取待处理的原始节点数据
     * 
     * 必须实现
     * 
     * return \Illuminate\Support\Collection
     */
    public function getTreeAllNodes()
    {
        
    }
}

可用方法

public function setAllNodes(Collection $nodes)
public function getSubLevel($parentId)
public function getDescendants($parentId, $depth = 0, $adds = '')
public function getLayerOfDescendants($id)
public function getSelf($id)
public function getParent($id)
public function getAncestors($id, $depth = 0)

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

641,106,524 9,700
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

502,645,077 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

418,291,778 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

394,964,158 4,660

Version History

Version Released PHP Laravel License
v1.0.3 ~5.6|~7.0 5.3.*||5.4.* Apache-2.0
v1.0.2 >=5.6.4 5.3.* Apache-2.0
v1.0.1 >=5.6.4 5.3.* Apache-2.0
v1.0.0 >=5.6.4 5.3.* Apache-2.0