Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.

My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.


Introduction

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
This pastie shows how the output of Zend_View_Helper_Navigation_Menu
can be controlled with the options minDepth, maxDepth, onlyActiveBranch,
and renderParents.

Available options (in addition to indent and ulClass):
minDepth (default: null)
maxDepth (default: null)
onlyActiveBranch (default: false)
renderParents (default: true)

Notes:
* Each use case shows a stripped-down text-only version of output from:
  $helper->renderMenu($container, $options)
* UC-1 shows the entire $container, and could be used as a reference point
  for the later use cases.
* Page 1 is on level 0 (along with Page 2 and Page 3). Page 2.1 is on
  level 2, Page 2.1.1 on level 3, etc.
* All use cases are implemented in an example PHP file at the bottom of 
  the paste. The only requirement is that the current ZF incubator is on
  your include_path.

UC-1: $options = array()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Page 1
Page 2
  Page 2.1
    Page 2.1.1
    Page 2.1.2
      Page 2.1.2.1
      Page 2.1.2.2
      Page 2.1.2.3
    Page 2.1.3
  Page 2.2
    Page 2.2.1
    Page 2.2.2
    Page 2.2.3
  Page 2.3
Page 3

UC-2: $options = array('maxDepth' => 1)

1
2
3
4
5
6
Page 1
Page 2
  Page 2.1
  Page 2.2
  Page 2.3
Page 3

UC-3: $options = array('minDepth' => 1)

1
2
3
4
5
6
7
8
9
10
11
12
Page 2.1
  Page 2.1.1
  Page 2.1.2
    Page 2.1.2.1
    Page 2.1.2.2
    Page 2.1.2.3
  Page 2.1.3
Page 2.2
  Page 2.2.1
  Page 2.2.2
  Page 2.2.3
Page 2.3

UC-4: $options = array('minDepth' => 1, 'maxDepth' => 2)

1
2
3
4
5
6
7
8
9
Page 2.1
  Page 2.1.1
  Page 2.1.2
  Page 2.1.3
Page 2.2
  Page 2.2.1
  Page 2.2.2
  Page 2.2.3
Page 2.3

UC-5: $options = array('onlyActiveBranch' => true)

1
2
3
4
5
6
7
// deepest active page is Page 2.1.2 (level 2)
Page 2
  Page 2.1
    Page 2.1.2
      Page 2.1.2.1
      Page 2.1.2.2
      Page 2.1.2.3

UC-6: $options = array('onlyActiveBranch' => true, 'renderParents' => false)

1
2
3
4
// deepest active page is Page 2.1.2 (level 2)
Page 2.1.2.1
Page 2.1.2.2
Page 2.1.2.3

UC-7: $options = array('minDepth' => 1, 'onlyActiveBranch' => true)

1
2
3
4
5
6
// deepest active page is Page 2.1.2 (level 2)
Page 2.1
  Page 2.1.2
    Page 2.1.2.1
    Page 2.1.2.2
    Page 2.1.2.3

UC-8: $options = array('maxDepth' => 2, 'onlyActiveBranch' => true)

1
2
3
4
5
6
// deepest active page is Page 2.1.2 (level 2)
Page 2
  Page 2.1
    Page 2.1.1
    Page 2.1.2
    Page 2.1.3

UC-9: $options = array('minDepth' => 1, 'maxDepth' => 2, onlyActiveBranch' => true)

1
2
3
4
5
// deepest active page is Page 2.1.2 (level 2)
Page 2.1
  Page 2.1.1
  Page 2.1.2
  Page 2.1.3

UC-10: $options = array('minDepth' => 2, 'maxDepth' => 2, 'onlyActiveBranch' => true)

1
2
3
4
// deepest active page is Page 2.1.2.2 (level 3)
Page 2.1.1
Page 2.1.2
Page 2.1.3

menu-uc.php (php)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
// a simple file to run the 10 menu use cases
// usage: php menu-uc.php

// setup
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
$view = new Zend_View();

// create container
$container = new Zend_Navigation(array(
    array(
        'label' => 'Page 1',
        'uri'   => '#'
    ),
    array(
        'label' => 'Page 2',
        'uri'   => '#',
        'pages' => array(
            array(
                'label' => 'Page 2.1',
                'uri'   => '#',
                'pages' => array(
                    array(
                        'label' => 'Page 2.1.1',
                        'uri'   => '#'
                    ),
                    array(
                        'label' => 'Page 2.1.2',
                        'uri'   => '#',
                        'pages' => array(
                            array(
                                'label' => 'Page 2.1.2.1',
                                'uri'   => '#'
                            ),
                            array(
                                'label' => 'Page 2.1.2.2',
                                'uri'   => '#'
                            ),
                            array(
                                'label' => 'Page 2.1.2.3',
                                'uri'   => '#'
                            )
                        )
                    ),
                    array(
                        'label' => 'Page 2.1.3',
                        'uri'   => '#'
                    )
                )
            ),
            array(
                'label' => 'Page 2.2',
                'uri'   => '#',
                'pages' => array(
                    array(
                        'label' => 'Page 2.2.1',
                        'uri'   => '#'
                    ),
                    array(
                        'label' => 'Page 2.2.2',
                        'uri'   => '#'
                    ),
                    array(
                        'label' => 'Page 2.2.3',
                        'uri'   => '#'
                    )
                )
            ),
            array(
                'label' => 'Page 2.3',
                'uri'   => '#'
            )
        )
    ),
    array(
        'label' => 'Page 3',
        'uri'   => '#'
    )
));

$useCases = array(
    1 => array(),
    2 => array('maxDepth' => 1),
    3 => array('minDepth' => 1),
    4 => array('minDepth' => 1, 'maxDepth' => 2),
    5 => array('onlyActiveBranch' => true),
    6 => array('onlyActiveBranch' => true, 'renderParents' => false),
    7 => array('minDepth' => 1, 'onlyActiveBranch' => true),
    8 => array('maxDepth' => 2, 'onlyActiveBranch' => true),
    9 => array('minDepth' => 1, 'maxDepth' => 2, 'onlyActiveBranch' => true),
    10 => array('minDepth' => 2, 'maxDepth' => 2, 'onlyActiveBranch' => true)
);

foreach ($useCases as $uc => $options) {
    if ($uc == 10) {
        $active = $container->findByLabel('Page 2.1.2.2');
        $active->active = true;
    } elseif ($uc > 4) {
        $active = $container->findByLabel('Page 2.1.2');
        $active->active = true;
    }

    echo 'UC-', $uc, ':', PHP_EOL;
    echo $view->navigation()->menu()->renderMenu($container, $options);
    echo PHP_EOL, PHP_EOL;

    if ($uc > 4) {
        $active->active = false;
    }
}