Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Nested Set Tree as HTML List
I'm trying to create an HTML list (UL) out of a nested set tree, to create a menu from it.
After spending 6+ hours and spinning my head I still couldn't find a good solution.
I Googled every where without any luck.
I've put the code (very dirty code still) for anyone to have a look and advise, please.
You need to use recursion to do this properly.
Start by passing the tree root to the method. In the method, open the UL, fetch all children, and for every child, create an LI. If the child is not a leaf node, don't close with /LI, but recurse first, inserting a nested UL for that node. And so on...
Thanks for the tip! "Recursion" is the magic word I was looking for.
I found an nice article that had what I need:
The other wrong thing I was doing is using the $tree->descendants() instead of $tree->children()
Here's the final result for anyone in need:
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion