重置 Zend_Navigation 状态

发布于 2024-12-13 16:21:43 字数 1270 浏览 2 评论 0原文

我目前正在构建一个应用程序,我可以通过多种方式访问​​同一控制器。

例如:

Presenters -> access controller user/index with param user_type : presenters
Attendees -> access controller user/index with param user_type : attendees

在我的导航 .ini 中,我定义了两个路径(我删除了标签、模块和 ACL 以方便阅读):

dashboard.pages.presenter.controller = "user"
dashboard.pages.presenter.action = "index"

dashboard.pages.presenter.pages.create.controller = "user"
dashboard.pages.presenter.pages.create.action = "create"

dashboard.pages.presenter.pages.edit.controller = "user"
dashboard.pages.presenter.pages.edit.action = "edit" 

dashboard.pages.attendee.controller = "user"
dashboard.pages.attendee.action = "index"

dashboard.pages.attendee.pages.create.controller = "user"
dashboard.pages.attendee.pages.create.action = "create"

dashboard.pages.attendee.pages.edit.controller = "user"
dashboard.pages.attendee.pages.edit.action = "edit"

我遇到的问题是,当我转到与会者部分时,显示的面包屑是一份给主持人。我知道它按预期工作,但我正在寻找一种方法来根据 URL 参数 user_type 将正确的“节点”设置为活动状态。

使用这个:

$page = $this->view->navigation()->findOneByLabel($label);
if ($page) {
    $page->setActive();
}

我已经能够将页面设置为活动状态,但我正在寻找一种将 Zend_Navigation 状态“重置”为无的方法。

I am currently building an application where I have multiple ways to access the same controller.

E.g.:

Presenters -> access controller user/index with param user_type : presenters
Attendees -> access controller user/index with param user_type : attendees

In my navigation .ini I have defined both paths (I removed the label, the module and ACL to ease the reading):

dashboard.pages.presenter.controller = "user"
dashboard.pages.presenter.action = "index"

dashboard.pages.presenter.pages.create.controller = "user"
dashboard.pages.presenter.pages.create.action = "create"

dashboard.pages.presenter.pages.edit.controller = "user"
dashboard.pages.presenter.pages.edit.action = "edit" 

dashboard.pages.attendee.controller = "user"
dashboard.pages.attendee.action = "index"

dashboard.pages.attendee.pages.create.controller = "user"
dashboard.pages.attendee.pages.create.action = "create"

dashboard.pages.attendee.pages.edit.controller = "user"
dashboard.pages.attendee.pages.edit.action = "edit"

The issue I am having is that when i go to the attendee section, the breadcrumb that is displayed is the one for the presenters. I understand that it work as intended, but I am looking for a way to set the right "node" active based on the URL param user_type.

Using this :

$page = $this->view->navigation()->findOneByLabel($label);
if ($page) {
    $page->setActive();
}

I have been able to set a page to active, but I am looking for a way to "reset" the Zend_Navigation state to none.

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

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

发布评论

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

评论(1

戏蝶舞 2024-12-20 16:21:43

只要我让你正确地将其放入你的 Bootstrap 中并复制我为你编写的控制器插件。我还没有测试如果没有为视图设置导航会发生什么。最好测试一下。顺便说一句,使用不同路由的相同页面对于搜索引擎优化来说并不好。

引导程序:

protected function _initStackoverflow()
{
    $this->bootstrap('frontController');
    $frontController = $this->getResource( 'frontController' );
    $frontController->registerPlugin( new Altergear_Controller_Plugin_Stackoverflow() );
}

控制器插件:

<?php
class Altergear_Controller_Plugin_Stackoverflow extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch( Zend_Controller_Request_Abstract $request )
    {
        if( ( $activeLabel = $this->_request->getUserParam('active') ) !== null ){
            $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->bootstrap('view')->getResource('view'); 
            foreach( $view->navigation()->getPages() as $page )
            {
                $page->setActive(  strtolower( $page->getLabel() ) === strtolower( $activeLabel ) );
            }
        }
    }
}

As long as I got you right put this in your Bootstrap and copy the controller plugin I wrote for you. I did not test yet what happens if no navigation was set to the view. Better test that. By the way having equal pages using different routes is not good in terms of seo.

Bootstrap:

protected function _initStackoverflow()
{
    $this->bootstrap('frontController');
    $frontController = $this->getResource( 'frontController' );
    $frontController->registerPlugin( new Altergear_Controller_Plugin_Stackoverflow() );
}

Controller Plugin:

<?php
class Altergear_Controller_Plugin_Stackoverflow extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch( Zend_Controller_Request_Abstract $request )
    {
        if( ( $activeLabel = $this->_request->getUserParam('active') ) !== null ){
            $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->bootstrap('view')->getResource('view'); 
            foreach( $view->navigation()->getPages() as $page )
            {
                $page->setActive(  strtolower( $page->getLabel() ) === strtolower( $activeLabel ) );
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文