1. Go to this page and download the library: Download gtcesar/recursive-db-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/ */
gtcesar / recursive-db-tree example snippets
/**
* Segment
*
* Represents a segment entity in the database.
* Extends TRecord, the base class for database records in Adianti Framework.
*/
class Segment extends TRecord
{
const TABLENAME = 'segment'; // Name of the database table
const PRIMARYKEY = 'id'; // Primary key field name
const IDPOLICY = 'serial'; // ID generation policy (max, serial)
/**
* Constructor method
*
* @param int|null $id The ID of the segment (optional)
* @param bool $callObjectLoad Whether to call the parent's load method (default: TRUE)
*/
public function __construct($id = NULL, $callObjectLoad = TRUE)
{
// Call the parent constructor to initialize the object
parent::__construct($id, $callObjectLoad);
// Add attributes to the record
parent::addAttribute('parent_segment_id'); // Parent segment ID
parent::addAttribute('description'); // Segment description
parent::addAttribute('icon_class'); // Icon class for the segment
}
}
use Gtcesar\RecursiveDBTree\RecursiveDBTree;
/**
* SegmentTree
*
* This class represents a segment tree page.
* It displays a hierarchical structure of segments using RecursiveDBTree component.
* Users can interact with the segments by selecting, editing, deleting, or viewing them.
*/
class SegmentTree extends TPage
{
/**
* Class constructor
* Creates the page and initializes its components
*/
function __construct()
{
parent::__construct();
// Create a panel
$panel = new TPanelGroup('Segment');
// Create a RecursiveDBTree instance to display segments
$segment = new RecursiveDBTree('segment', 'app', 'Segment', 'id', 'parent_segment_id', 'description', 'id asc', null, 'icon_class');
$segment->collapse();
// $segment->setDefaultTreeIconClass('fas fa-folder'); // Optional: Set a default icon for all nodes
// Set an action when selecting an item
$segment->setItemAction(new TAction(array($this, 'onSelect')));
// Add options to the context menu
$segment->addContextMenuOption('Edit', new TAction([$this, 'onEdit']), 'fas fa-edit');
$segment->addContextMenuOption('Delete', new TAction([$this, 'onDelete']), 'fas fa-trash-alt');
$segment->addContextMenuOption('View', new TAction([$this, 'onView']), 'fas fa-eye');
$panel->add($segment);
// **Note on Font Awesome:** This plugin assumes that Font Awesome is already
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.