我应该在哪里填充我的 Zend_Navigation 容器?

发布于 2024-11-02 11:56:48 字数 81 浏览 1 评论 0原文

我应该在应用程序中的哪个位置定义顶级和较低级别的页面以供 Zend Navigation 使用?我的顶级导航栏视图助手将与生成子导航的视图助手分开。

Where in my application should I define my top level and lower-level pages for use by Zend Navigation? My top level navigation bar view helper is going to be separate from the view helper that generates the sub navigation.

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

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

发布评论

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

评论(2

寂寞清仓 2024-11-09 11:56:48

一种更简单的方法是在一个地方定义所有导航。它支持无限嵌套(子)页面,这意味着您可以将主菜单作为基本级别,然后将每个主页面下的子页面作为子菜单。使用视图助手,您可以轻松地自动仅输出当前活动页面的子页面菜单。

这样可以将所有导航保留在一个位置,以便将来进行维护。

例如,我使用 应用程序资源,然后在我的视图脚本中使用 导航视图助手来格式化我的菜单。

这是我正在处理的项目中的 application.ini 文件导航配置的一小段摘录:

resources.navigation.pages.exhibits.label                   = "Exhibits"
resources.navigation.pages.exhibits.controller              = "exhibits"
resources.navigation.pages.exhibits.action                  = "index"
resources.navigation.pages.exhibits.pages.index.label       = "Search Exhibitors"
resources.navigation.pages.exhibits.pages.index.controller  = exhibits
resources.navigation.pages.exhibits.pages.index.action      = index
resources.navigation.pages.exhibits.pages.search.label      = "Search Exhibits"
resources.navigation.pages.exhibits.pages.search.controller = exhibits
resources.navigation.pages.exhibits.pages.search.action     = "search"
resources.navigation.pages.exhibits.pages.new.label         = "New Exhibitor"
resources.navigation.pages.exhibits.pages.new.controller    = exhibits
resources.navigation.pages.exhibits.pages.new.action        = "new"
resources.navigation.pages.exhibits.pages.import.label      = "Import Exhibits"
resources.navigation.pages.exhibits.pages.import.controller = exhibits
resources.navigation.pages.exhibits.pages.import.action     = "import"

resources.navigation.pages.sales.label                      = "Sales"
resources.navigation.pages.sales.controller                 = "sales"
resources.navigation.pages.sales.action                     = index
resources.navigation.pages.sales.pages.index.label          = "Review/Search"
resources.navigation.pages.sales.pages.index.controller     = sales
resources.navigation.pages.sales.pages.index.action         = index
resources.navigation.pages.sales.pages.edit.label           = Add/Edit Sales
resources.navigation.pages.sales.pages.edit.controller      = sales
resources.navigation.pages.sales.pages.edit.action          = edit
resources.navigation.pages.sales.pages.flags.label          = Flags/Problems
resources.navigation.pages.sales.pages.flags.controller     = sales
resources.navigation.pages.sales.pages.flags.action         = flags

在我的 layout.phtml 文件中:

<div id='mainmenu'>
  <?php echo $this->navigation()->menu()->setMaxDepth(0); ?>
</div> <!-- #mainmenu -->
<div id='submenu'>
  <?php echo $this->navigation()->menu()->setOnlyActiveBranch(true)
                                        ->setMinDepth(1)
                                        ->setMaxDepth(1); ?>
</div> <!-- #submenu -->

因此,当用户转到“展览”页面时,他们只能看到该页面的子页面,并且与销售页面相同。非常简单而且非常有效。

A simpler way is to define all your navigation in a single place. It supports unlimited nested (child) pages, meaning you can have your main menu as the base level and then the sub-pages under each main page for your sub-menus. Using the View Helpers you can easy output only the sub-page menu for the current active page automatically.

This way keeps all your navigation in a single place, for future maintainability.

For example, I define my site-wide navigation within the application.ini file using the Application Resource, and then within my view scripts use the Navigation View Helpers to format my menus.

This is a small extract from my application.ini file navigation config in a project I am working on:

resources.navigation.pages.exhibits.label                   = "Exhibits"
resources.navigation.pages.exhibits.controller              = "exhibits"
resources.navigation.pages.exhibits.action                  = "index"
resources.navigation.pages.exhibits.pages.index.label       = "Search Exhibitors"
resources.navigation.pages.exhibits.pages.index.controller  = exhibits
resources.navigation.pages.exhibits.pages.index.action      = index
resources.navigation.pages.exhibits.pages.search.label      = "Search Exhibits"
resources.navigation.pages.exhibits.pages.search.controller = exhibits
resources.navigation.pages.exhibits.pages.search.action     = "search"
resources.navigation.pages.exhibits.pages.new.label         = "New Exhibitor"
resources.navigation.pages.exhibits.pages.new.controller    = exhibits
resources.navigation.pages.exhibits.pages.new.action        = "new"
resources.navigation.pages.exhibits.pages.import.label      = "Import Exhibits"
resources.navigation.pages.exhibits.pages.import.controller = exhibits
resources.navigation.pages.exhibits.pages.import.action     = "import"

resources.navigation.pages.sales.label                      = "Sales"
resources.navigation.pages.sales.controller                 = "sales"
resources.navigation.pages.sales.action                     = index
resources.navigation.pages.sales.pages.index.label          = "Review/Search"
resources.navigation.pages.sales.pages.index.controller     = sales
resources.navigation.pages.sales.pages.index.action         = index
resources.navigation.pages.sales.pages.edit.label           = Add/Edit Sales
resources.navigation.pages.sales.pages.edit.controller      = sales
resources.navigation.pages.sales.pages.edit.action          = edit
resources.navigation.pages.sales.pages.flags.label          = Flags/Problems
resources.navigation.pages.sales.pages.flags.controller     = sales
resources.navigation.pages.sales.pages.flags.action         = flags

And within my layout.phtml file:

<div id='mainmenu'>
  <?php echo $this->navigation()->menu()->setMaxDepth(0); ?>
</div> <!-- #mainmenu -->
<div id='submenu'>
  <?php echo $this->navigation()->menu()->setOnlyActiveBranch(true)
                                        ->setMinDepth(1)
                                        ->setMaxDepth(1); ?>
</div> <!-- #submenu -->

So when a user goes to the Exhibits page, they only see the children of that page, and the same with the Sales page. Pretty simple and very effective.

孤凫 2024-11-09 11:56:48

我通常在控制器插件中执行此操作。在这里,我可以根据当前路线或请求参数创建导航,然后在重新设计导航时轻松地从应用程序资源传递到视图/布局并切换到另一个视图/布局。

I usually do this in the controller plugin. Here I can create navigation based on the current route or request parameters, and then easily pass to the view/layout from the application resource and switch with another one, when navigation is redesigned.

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