1. Go to this page and download the library: Download allegiance-group/nested-set library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
allegiance-group / nested-set example snippets
// Create Config object with DSN data
$config = Config::createWithDsn('mysql:dbname=some_database;host=localhost', 'some_user', 'some_password');
// Set table name
$config->table = 'some_table';
// If we don't want to retrieve all columns when using find methods
// we specify which columns we want to fetch
$config->columns = ['column1', 'column5', 'alias_of_column' => 'column7'];
// You can also instruct methods from Find class to
// Create an instance of Manipulate class
$manipulate = new Manipulate($config);
// Create a root node on an empty table
$rootId = $manipulate->createRootNode();
// Create a node
$node1 = $manipulate->insert($rootId, ['column1' => 'some data', 'column2' => 'some more data']);
// Create another node that is child/leaf of first node
$node2 = $manipulate->insert($node, ['column1' => 'child data', 'column2' => 'some more child data']);
// Move node2 so it is on same level as node1
$manipulate->moveAfter($node2, $node1);
// Or we could have moved it in front of node1
$manipulate->moveBefore($node2, $node1);
// Move node2 back to its original position (as child of node1)
$manipulate->moveMakeChild($node2, $root1);
// Delete a node (and all its children, if any)
$manipulate->delete($node);
// You can also empty a node by delete all of its descendants
// or enter a node identifier as second parameter to move descendants to a new location
$manipulate->clean($parentNode, $destinationNode);
$manipulate->moveBefore([5,6,26,88], 33);
// Create instance of Find class
$find = new Find($config);
$find->findAncestors();
$find->findParent();
$find->findDescendants();
$find->findChildren();
$find->findFirstChild();
$find->findLastChild();
$find->findSiblings();
$find->findNextSibling();
$find->findPreviousSibling();