开发者

Zend_Navigation isActive not working

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜