可能重复:
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));
utilityId
和mainMenuId
属性是从数据库中获取的数字。
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
,也许我会尝试一下。