2017 © Pedro Peláez
 

library nestedset-php

A PDO plugin implementing the nested set pattern

image

ben-nsng/nestedset-php

A PDO plugin implementing the nested set pattern

  • Wednesday, June 24, 2015
  • by ben-nsng
  • Repository
  • 4 Watchers
  • 11 Stars
  • 487 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 2 Versions
  • 5 % Grown

The README.md

nestedset-php

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, (*1)

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., (*2)

# 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)
  • Inspired by [MySQL stored procedures to manage hierarchical trees in a MySQL database] (http://moinne.com/blog/ronald/mysql/manage-hierarchical-data-with-mysql-stored-procedures)
  • [Nested Set Model] (http://en.wikipedia.org/wiki/Nested_set_model)
  • [Managing Hierarchical Data in MySQL] (http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/)
  • [Storing Hierarchical Data in a Database] (http://www.sitepoint.com/hierarchical-data-database/)

Authors

The Versions

24/06 2015

dev-master

9999999-dev

A PDO plugin implementing the nested set pattern

  Sources   Download

MIT

by Ben Ng

24/06 2015

v0.0.1

0.0.1.0

A PDO plugin implementing the nested set pattern

  Sources   Download

MIT

by Ben Ng