PHP code example of alex-kalanis / nested-tree

1. Go to this page and download the library: Download alex-kalanis/nested-tree 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/ */

    

alex-kalanis / nested-tree example snippets


class MyNodes extends \kalanis\nested_tree\Support\Node
{
    public ?string $my_column = null;
}

class MyTable extends \kalanis\nested_tree\Support\TableSettings
{
    public string $tableName = 'my_menu';
}

$myNodes = new MyNodes();
$myTable = new MyTable();

// this is usually set via DI
$actions = new \kalanis\nested_tree\Actions(
    new \kalanis\nested_tree\NestedSet(
        new \kalanis\nested_tree\Sources\PDO\MySql(
            $yourPDOconnection,
            $myNodes,
            $myTable,
        ),
        $myNodes,
        $myTable,
    ),
);

// now work:

// repair the whole structure
$actions->fixStructure();

// move node in row
$actions->movePosition(25, 3);

// change parent node for the one chosen
$actions->changeParent(13, 7);