Zend_Navigation 的自定义渲染

发布于 2024-08-16 02:28:02 字数 514 浏览 11 评论 0原文

我将导航 XML 文件与我的 Zend Framework MVC 应用程序结合使用。

顶级菜单呈现在布局的顶部。生成它的代码如下所示:

$this->navigation()->menu()->renderMenu(null,array('maxDepth'   =>  0));

这将自动呈现我已在顶部菜单中设置样式的链接的无序列表。 现在,我想利用所有内置 Zend_Navigation 优点(MVC 和 ACL 集成)但使用自定义标记来渲染子菜单(以渲染活动容器树)。我会通过插入以下内容来做到这一点:

$this->navigation()->menu()->renderSubMenu();

事实上,我有一组非常具体的标记,我需要用它们来呈现它。它是如此的截然不同,我认为我无法设计一个无序列表来适应我想要的演示文稿。

有没有一种简单的方法(或者如果需要的话可以复杂一点;)来自定义子菜单?

I am using a navigation XML file in conjunction with my Zend Framework MVC app.

A top level menu is rendered at the top of my layout. The code to produce it looks like this:

$this->navigation()->menu()->renderMenu(null,array('maxDepth'   =>  0));

This will automatically render an unordered list of links that I have styled into my top menu.
Now, I want to render the submenu (to render the active container tree) taking advantage of all the built-in Zend_Navigation goodness (MVC and ACL integration) but with custom markup. I would do this by inserting this:

$this->navigation()->menu()->renderSubMenu();

In fact, I have a very specific set of markup that I need to render this with. It is so drastically different I do not think I could style an unordered list to accomodate my desired presentation.

Is there a simple way (or complicated if need be ;) to customize a submenu?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

余生再见 2024-08-23 02:28:02

看看我的这个答案: 让 Zend_Navigation 菜单正常工作通过 jQuery 的 Fisheye

总结,您可以创建一个用于导航的视图并循环浏览页面,并使用页面方法创建自定义标记。据我所知,目前导航没有类似装饰器的支持。

Check out this answer of mine: Getting Zend_Navigation menu to work with jQuery's Fisheye

Summarized, you create a view for the navigation and loop through the pages and use the page methods to create custom markup. As far as I know, there's no decorator-like support for Navigation currently.

-残月青衣踏尘吟 2024-08-23 02:28:02

Typeoneerror 让我走上了正轨,这是我最终使用的代码:

在layout.phtml中:

<?= $this->navigation()->menu()->renderMenu(null,array('maxDepth'   =>  0)); ?>
<? $this->navigation()->menu()->setPartial('sidemenu.phtml'); ?>
<?= $this->navigation()->menu()->render(); ?>

在sidemenu.phtml中:

$this->navigation()->findByResource(
  Zend_Controller_Front::getInstance()->getRequest()->module .
  Zend_Controller_Front::getInstance()->getRequest()->controller
 );

 foreach ($this->container as $page) {
    if ($page->isVisible() && $this->navigation()->accept($page)) {
        if ($page->isActive()) {
            echo $page->getLabel();
            $subcontainer = $page->getPages();
            foreach ($subcontainer as $subpage) {
                echo $subpage->getLabel();
            }
        }
    }
 }

工作得像一个魅力,将其作为答案供其他人查找。

Typeoneerror put me on the right track, here is the code I ended up using:

In layout.phtml:

<?= $this->navigation()->menu()->renderMenu(null,array('maxDepth'   =>  0)); ?>
<? $this->navigation()->menu()->setPartial('sidemenu.phtml'); ?>
<?= $this->navigation()->menu()->render(); ?>

In sidemenu.phtml:

$this->navigation()->findByResource(
  Zend_Controller_Front::getInstance()->getRequest()->module .
  Zend_Controller_Front::getInstance()->getRequest()->controller
 );

 foreach ($this->container as $page) {
    if ($page->isVisible() && $this->navigation()->accept($page)) {
        if ($page->isActive()) {
            echo $page->getLabel();
            $subcontainer = $page->getPages();
            foreach ($subcontainer as $subpage) {
                echo $subpage->getLabel();
            }
        }
    }
 }

Worked like a charm, leaving this as an answer for someone else to find.

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