Zend_Navigation:使用多个容器渲染面包屑时遇到问题

发布于 2024-08-14 15:26:47 字数 1781 浏览 11 评论 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 以及指向容器的属性。

看起来是同样的问题,有人建议使用 < 设置/获取它们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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

护你周全 2024-08-21 15:26:47

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

例如,

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

或者可能是其他东西,但这很难说。不过,我希望这会有所帮助!

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!

水溶 2024-08-21 15:26:47

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

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

并像这样吐出:

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文