For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > September 2007 > Re: [PEAR] HTML Menu/DBNested - Only want to display tree with 2









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] HTML Menu/DBNested - Only want to display tree with 2
Alexey Borzov

2007-09-18, 7:09 pm

Hi,

Mark Reynolds wrote:
> I have an array which I'm trying to display as a 'Tree' menu via 'HTML
> Menu' (example of the actual tree menu below, the array is below that). I've
> come across a few problems. Firstly, as you would expect when the 'tree'
> menu is displayed it displays three levels. Because I'm using the
> DirectTreeRenderer the menu is displayed in a list and I'm trying to find a
> way of just displaying 2 levels. Is this something I can limit as part of
> HTML menu or is it something I have to put in place when creating the actual
> array and if so, how do I do it? I've looked at


You can use something like this on $structure array you get from NestedSet
before passing it to HTML_Menu:

function trimTree(&$tree, $level)
{
foreach (array_keys($tree) as $key) {
if (!empty($tree[$key]['sub'])) {
if (1 == $level) {
unset($tree[$key]['sub']);
} else {
$this->trimTree($tree[$key]['sub'], $level - 1);
}
}
}
}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com