ben-nsng/nestedset-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ben-nsng/nestedset-php

最新稳定版本:v0.0.1

Composer 安装命令:

composer require ben-nsng/nestedset-php

包简介

A PDO plugin implementing the nested set pattern

README 文档

README

If you are not using any PHP framework and need to manage tree structure data, here is the library using Nested Sets Pattern to Model Tree Structure in PHP

Installation

To install the library, you can simply clone the library and include the file pdo.nestedset.php. If you are using Composer in your project, it is really simple to install nestedset-php.

# Install Composer
curl -sS https://getcomposer.org/installer | php

# Add nestedset-php as a dependency
php composer.phar require ben-nsng/nestedset-php:*

Usage

$pdo = new PDO('mysql:host=localhost;dbname=tree', 'tree', 'tree');
$treeModel = new NestedSet($pdo);
$treeModel->changeTable('tree'); // default table is tree

API

Instance methods:

// init table for first creating table
$treeModel->addRoot();

// add new node to root node, return node id
$treeModel->addNode($label);

// add new node into parent node return node id
$treeModel->addNode($label, $parent_id);

// return database statement object
$nodes = $treeModel->selectAll();
// array of nodes (stdclass)
$nodes->result();

// move existing node into parent node
$treeModel->addChild($node_id, $parent_id);

// move existing node before next node
$treeModel->addBefore($node_id, $next_id);

// move existing node after last node
$treeModel->addBefore($node_id, $last_id);

// delete existing node, including nodes inside node
$treeModel->deleteNode($node_id)

Related Links/Resources

Authors

统计信息

  • 总下载量: 7.53k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 23
  • Watchers: 6
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-24