1

I have the following code:

<ul class="navigation">
    <?php foreach( $this->navigation as $item ): ?>
    <li class="<?php if($item->isActive()){echo " active";}?>">
            <div class="shadow"></div>
            <div class="tab"><?php echo $this->htmlLink($item->getHref(), $this->translate($item->getLabel())) ?></div>

      </li>
    <?php endforeach; ?>
</ul>

The $item->isActive() works as intended only for the home page. on all the other pages the class="active" does not show up.

UPDATE:

The application uses route such as the following:

// Routes --------------------------------------------------------------------
  'routes' => array(
    'home' => array(
      'route' => '/',
      'defaults' => array(
        'module' => 'core',
        'controller' => 'index',
        'action' => 'index'
      )
    ),
    'core_home' => array(
      'route' => '/',
      'defaults' => array(
        'module' => 'core',
        'controller' => 'index',
        'action' => 'index'
      )
    ),
    'confirm' => array(
      'route'=>'/confirm',
      'defaults' => array(
        'module'=>'core',
        'controller'=>'confirm',
        'action'=>'confirm'
      )
    ),

    // Admin - General
    'core_admin_settings' => array(
      'route' => "admin/core/settings/:action/*",
      'defaults' => array(
        'module' => 'core',
        'controller' => 'admin-settings',
        'action' => 'index'
      ),
      'reqs' => array(
        'action' => '\D+',
      )
    ),
  )

the routes are save in a file called manifest.php

Samuel
  • 781
  • 5
  • 22
  • probably something with your navigation items, or your router (if you have one) give example of your navigation items, active items require many things to be set up properly – venimus Jun 16 '11 at 14:52

2 Answers2

1

If you are using custom routes while creating your Zend_Navigation_Page_Mvc objects, you have to set Module, Controller and Action explicitly.

See the Zend_Navigation Documentation under Example #4 Using routes:

Note: Note that when using the route property in a page, you should also specify the default params that the route defines (module, controller, action, etc.), otherwise the isActive() method will not be able to determine if the page is active.

If you are not using Routes, please provide some more informations about your Code.


Concerning your update:

Your Zend_Navigations has to look like the following

new Zend_Navigation(array(
    array(
        'label'     => 'Home',
        'module'    => 'core',
        'controller'=> 'index',
        'action'    => 'index',
        'route'     => 'core'
    ),
    array(
        'label'     => 'Admin Settings',
        'module'    => 'core',
        'controller'=> 'admin-settings',
        'action'    => 'index',
        'route'     => 'core_admin_settings'
    ),
    array(
        'label'     => 'User Administration',
        'module'    => 'core',
        'controller'=> 'admin-settings',
        'action'    => 'users',
        'route'     => 'core_admin_settings'
    ),
));

Then, the isActive() method should work like expected.

Matthias Bayer
  • 1,169
  • 1
  • 8
  • 15
  • How do I specify the default params? The applications has many modules all with their own routes and we can add in the main menu any of these module. – Samuel Jun 17 '11 at 10:00
  • The example number 4 does not really help me because from what I added above each module has its route array in the manifest.php and I do not see how to make it work according to example number 4. – Samuel Jun 17 '11 at 10:12
  • You have two options. First, you just take a look at your routes and copy the values of module, controller and action. Or, get an instance of you Router and get this informations from there (_getRoute_()) if you know the route name. – Matthias Bayer Jun 17 '11 at 10:19
0

If you didn't specify module, controller and action variable, You cannot use isActive() method unfortunetly

Dmitry Z.
  • 424
  • 6
  • 16