PHP code example of helbrary / node-item-tree
1. Go to this page and download the library: Download helbrary/node-item-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/ */
helbrary / node-item-tree example snippets
sh
foreach ($tree->findRootNodes() as $rootCategories) {
foreach ($node->findNodes() as $subCategory) {
echo $subCategory->getValue(); // name of category
foreach ($subcategory->findItems() as $product) {
echo "- " . $product->getValue(); // name of product
}
}
}
sh
$pathToNodes = $tree->getPathToNode(5);
foreach ($pathToNodes as $node) {
echo '- ' . $node->getValue();
}
// output will be: All categories - Computer - Gaming computer
// if we do not want render last node 'Gaming computer' then we must set second parameter of method getPathToNode to FALSE
$pathToNodes = $tree->getPathToNode(5, FALSE);
foreach ($pathToNodes as $node) {
echo '- ' . $node->getValue();
}
// output will be: All categories - Computer