Zend_Navigation:使用多个容器渲染面包屑时遇到问题
可能的重复:
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
以及指向容器的属性。
这看起来是同样的问题,有人建议使用 < 设置/获取它们code>Zend_Registry,也许我会尝试一下。
Possible Duplicate:
Zend Framework - multiplate navigation blocks
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑您没有导航层次结构。您需要页中页。
例如,
通过上述内容,面包屑将呈现在除主页之外的所有活动页面上...如果您这样做,则所有页面:
或者可能是其他东西,但这很难说。不过,我希望这会有所帮助!
I suspect you don't have a navigational hierarchy. You need pages within pages.
e.g.
With the above, breadcrumbs will be rendered on all active pages except for the Home Page... all pages if you do this:
Or maybe it's something else, but it's hard to say. I hope that helps, though!
这可能是一个肮脏的解决方案,但我使用 Zend_Registry 手动设置容器引用,如下所示:
并像这样吐出:
This is probably a dirty solution, but I manually set the container reference using Zend_Registry like so:
And spit it out like so: