0

可能重复:
Zend Framework - 多板导航块

我试图让面包屑在我的应用程序中呈现(它们不会出现在任何地方,甚至没有出现在主页上,它有一个相应的 Zend Page Uri 对象),它有多个导航区域 - 主要和实用程序。对于菜单生成,我有一个 MenuController,我使用以下方法从布局中渲染它:

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

utilityIdmainMenuId属性是从数据库中获取的数字。

Menu 控制器的 render 方法只是构建一个数组并创建一个 Zend Navigation 对象,然后调用 setContainer 并将其设置为该容器。这是伪代码,因为它相当长:

// 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;
    }
}

所以这个渲染方法在实用程序和导航的布局中被调用了两次。

编辑: 我认为问题是我需要指定 $container 所以我的代码是

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

但是,因为我使用$this->action('render', 'menu' )$container变量是在那里设置的并且没有返回,有没有办法可以通过其他方式指定容器?可能使用$this->layout()->nav和指向容器的属性。

看起来是同一个问题,有人建议使用 设置/获取它们Zend_Registry,也许我会尝试一下。

4

2 回答 2

1

我怀疑您没有导航层次结构。您需要页面中的页面。

例如

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

有了上述内容,面包屑将呈现在除主页之外的所有活动页面上......如果您这样做,则所有页面:

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

或者也许是别的什么,但很难说。我希望这会有所帮助!

于 2009-12-17T21:33:44.530 回答
0

这可能是一个肮脏的解决方案,但我使用 Zend_Registry 手动设置容器引用,如下所示:

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

像这样吐出来:

$main = Zend_Registry::get( 'nav' . $this->mainMenuId );
echo $this->navigation( $main )->breadcrumbs()->setMinDepth(0);
于 2009-12-20T22:59:43.980 回答