Re: HTML Menu/DBNested - Only want to display tree with 2 levels
| From: | Mark Reynolds | Date: | Thu, 20 Sep 2007 14:28:34 +0000 |
| Subject: | Re: HTML Menu/DBNested - Only want to display tree with 2 levels | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-27958@lists.php.net to get a copy of this message | ||
That's great Alexey, thanks alot, it works well.
"Alexey Borzov" <borz_off@cs.msu.su> wrote in message
news:46EFDE48.6060000@cs.msu.su...
> 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);
> }
> }
> }
> }