Question

i've got my navigation running and all links are working fine. Rendering the Navigation using $this->navigation($nav)->menu() will display an unordered list and all links are working.

Additionally the active link there is working, too. The active element has class="active" as an attribute.

Rendering the same navigation, only as a bradcrumb $this->navigation($nav)->breadcrumbs() doesn't render me anything. This MAY be due to my navigation only being one level deep for now, but imo the first level should still be rendered.

Using super modern die()-debugging i found out that nothing get's rendered because the findActive() of the viewHelper doesn't find an active element and therefore returns an empty string.

Any thoughts on where my error may be located? Any insight will be greatly appreciated. Here's my code so far:

'navigation' => array(
    'default' => array(
        'biete' => array(
            'label' => 'Biete',
            'route' => 'biete',
        ),
        'suche' => array(
            'label' => 'Suche',
            'route' => 'suche',
        ),
        'administration' => array(
            'label' => 'Administration',
            'route' => 'admin'
        ),
        'dashboard' => array(
            'label' => 'Meine Artikel',
            'route' => 'dashboard'
        ),
        'login' => array(
            'label' => 'Anmelden',
            'route' => 'duituser/login'
        ),
        'logout' => array(
            'label' => 'Abmelden',
            'route' => 'duituser/logout'
        )
    ),
),
'service_manager' => array(
    'factories' => array(
        'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
        'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
    ),
),

And the view Parts located in my layout.phtml

<?php echo $this->navigation('navigation')->menu(); ?>
<?php echo $this->navigation('navigation')->breadcrumbs(); ?>

Thanks again in advance.

Was it helpful?

Solution

I had a play with the Navigation classes/helper - it seems that breadcrumbs are rendered (in the example below) when the 'playground' route is matched. However by adding 'active' => true to my default route means it will always be rendered by the breadcrumb helper.

'navigation' => array(
     'default' => array(
        'test' => array(
            'label' => 'Home',
            'route' => 'test',
            'active' => true,
            'pages' => array(
                'playground' => array(
                    'label' => 'Playground',
                    'route' => 'playground',
                ),
            ),
        ),
    ),
 ),

OTHER TIPS

In addition to the answer of DrBeza, here is what helped me. The problem was that the Breadcrumb-Navigation only got rendered once we hit the second level. But you can obviously change that setting by calling the following:

$this->navigation('navigation')->breadcrumbs()->setMinDepth(0);

To me, this is all that was needed. As DrBeza pointed out however in some cases this may not be enough.

In my case helps only this this:

$this->navigation('navigation')->breadcrumbs()->render('navigation');

The strange is, that it's required only if $this->navigation('navigation')->menu() is called before, because breadcrumbs are not rendered.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top