Reset Zend_Navigation state

232 Views Asked by At

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.

1

There are 1 best solutions below

4
On BEST ANSWER

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 ) );
            }
        }
    }
}