1

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.

JF Dion
  • 4,014
  • 2
  • 24
  • 34
  • 1
    You could always create a new class for attendees that extends users. You get all the functions and remove the pain of playing with the nav. Plus you can add more custom functionality – Ashley Nov 03 '11 at 20:40

1 Answers1

1

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 ) );
            }
        }
    }
}
Jakob Alexander Eichler
  • 2,988
  • 3
  • 33
  • 49
  • Thanks for the SEO pointers, I now realize my error in designing my app, next time I will build a different controller for my differents users and delocalize most of my code. On the other hand your answer give the same result I was able to get but at a plugin level instead of inside the controller – JF Dion Nov 14 '11 at 16:50
  • Do not build a controller per user. Use Zend_AUth and Zend_Acl set a stdClass object as identity and append userId to it. This is how I work at the momemnt. – Jakob Alexander Eichler Nov 14 '11 at 17:56
  • I want your bounty. What part of your question is not yet answered :D ? – Jakob Alexander Eichler Nov 14 '11 at 17:57
  • Yeah, right, I didn't gave it to you at first because I was hoping for the solution to the current programmation probleme directly, but the bounty was about the answer or an alternative way of doing thing :P. After reading your solution I found a "hack" to do it like I wanted, but I am now stuck with an other problem, I will refactory my code to make it work properly. Thanks a lot – JF Dion Nov 14 '11 at 18:21