A CakePHP helper to handle tree structures.
By default, it uses the core TreeBehavior and MPTT (Modified Preorder Tree Traversal). But it sure can work with any tree like input as nested object or array structure.
Include helper in your AppView class as
$this->addHelper('Tools.Tree', [
...
]);
Then you can use it in your templates as
echo $this->Tree->generate($articles);
By default, just outputting the display name is usually not enough.
You want to create some Template/Element/tree_element.ctp element instead:
echo $this->Tree->generate($articles, ['element' => 'tree_element']);
That template can then contain all normal template additions, including full helper access:
<?php
/**
* @var \App\View\AppView $this
* @var \App\Model\Entity\Article|\Cake\Collection\CollectionInterface $data
*/
if (!$data->visible) { // You can do anything here depending on the record content
return;
}
?>
<li>
<?php echo $this->Html->link($data->title, ['action' => 'view', $data->id]); ?>
</li>
So the current entity object is available as $data variable inside this snippet.
plus all config values.
You can read some more tutorial like details in my blog post.