views:

366

answers:

2

Let's say, that we have:

$pages = array(
    array(
        'controller' => 'controller1',
        'label'      => 'Label1',
    ),
    array (
        'controller' => 'controller2',
        'label'      => 'Label2'
    ),
);
$container = new Zend_Navigation($pages);

When user clicks Label1, controller1/index action is rendered and Label1 becomes active state - everything is ok. On this page I have many links, such as: controller1/action1, controller1/action2, etc When one of these links is clicked, Label1 looses active state.

I understand, that I can add all sub-pages into Zend_Navigation, but there are plenty of these pages and I never need it anywhere for navigation, so, I'd prefer to have something like:

public function init()
{
    $this->view->navigation()-> ... get item by label ... -> setActive();
}

inside controller1. Is it possible?

+1  A: 

Your init method is very close!

$page = $this->view->navigation()->findOneByLabel('Your Label'); /* @var $page Zend_Navigation_Page */
if ( $page ) {
  $page->setActive();
}
Derek Illchuk
A: 

I think this is exactly what he is looking for: Simply paste this into your menu.phtml or any .phtml where you print your menu:

// apply active state to all actions of controller
$controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
$page = $this->navigation()->findOneByController($controller); /* @var $page Zend_Navigation_Page */
if ( $page ) {
  $page->setActive();
}
echo $this->navigation()->menu(); 

Of course you need to init first a navigation structure with Zend_Navigation_Page_Mvc pages. Somehow this does not work for me with url pages...

ZBI