Re: HTML Menu/DBNested - Only want to display tree with 2 levels
| From: | Alexey Borzov | Date: | Tue, 18 Sep 2007 14:18:48 +0000 |
| Subject: | Re: HTML Menu/DBNested - Only want to display tree with 2 levels | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-27949@lists.php.net to get a copy of this message | ||
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 atYou 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);
}
}
}
}