views:

418

answers:

3

I'm trying to make breadcrumbs render in my application ( they don't show up anywhere, not even the homepage, which has a corresponding Zend Page Uri object ), which has multiple navigation areas - primary and utility. For the menu generation, I have a MenuController which I render with from within the layout using:

$this->layout()->utility = $this->action('render', 'menu', null, array('menu' => $this->utilityId));
$this->layout()->nav = $this->action('render', 'menu', null, array('menu' => $this->mainMenuId));

The utilityId and mainMenuId properties are numbers, grabbed from a database.

The Menu controller's render method just builds an array and creates a Zend Navigation object, then invokes setContainer and sets it to that container. This is pseudo code because it's rather long:

// MenuController.php
private function renderAction() {
    $itemArray[] = array('label' => $label, 'uri' => $uri ); // in a loop
    $container = new Zend_Navigation($itemArray);
    if ( $container instanceof Zend_Navigation_Container ) {
       $this->view->navigation()->setContainer( $container );
       $uri = $this->_request->getPathInfo();
       $item = $this->view->navigation()->findByUri($uri);
       $item->active = true;
    }
}

So this render method is called twice from within the layout for the utility and nav.

EDIT: I think the issue is that I need to specify the $container so my code would be

$this->navigation($container)->breadcrumbs();

However because I'm using $this->action('render', 'menu' ) the $container variable is set there and not returned, is there a way I can specify the container some other way? Possibly using $this->layout()->nav and a property in that which points to the container.

This looks like it's the same issue and someone suggests setting/getting them with Zend_Registry, perhaps I'll try this out.

+1  A: 

Hey again, Meder.

I suspect you don't have a navigational hierarchy. You need pages within pages.

e.g.

Home Page
[pages] => Sign In
           [pages] => Forgot Password
        => Create Account
           [pages] => Confirm Account Email
                   => Email Confirmed

With the above, breadcrumbs will be rendered on all active pages except for the Home Page... all pages if you do this:

$this->navigation()->breadcrumbs()->setMinDepth(0); // don't skip the root page

Or maybe it's something else, but it's hard to say. I hope that helps, though!

Derek Illchuk
Ah. I don't have a hierarchy but it should at least spit out the breadcrumb for the homepage if I specified setMinDepth(0), right? Perhaps I'll make a test site and mess around with having a hierarchy.
meder
A: 

This is probably a dirty solution, but I manually set the container reference using Zend_Registry like so:

Zend_Registry::set( 'nav' . $menu, $container );

And spit it out like so:

$main = Zend_Registry::get( 'nav' . $this->mainMenuId );
echo $this->navigation( $main )->breadcrumbs()->setMinDepth(0);
meder
A: 

This may not be the whole answer you need, but it should get you a little further.

See: this answer

berty