1

我有以下代码:

<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>

$item->isActive()作品仅适用于主页。在所有其他页面上,class="active" 没有出现。

更新:

该应用程序使用如下路由:

// 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+',
      )
    ),
  )

路由保存在一个名为 manifest.php 的文件中

4

2 回答 2

1

如果您在创建Zend_Navigation_Page_Mvc对象时使用自定义路由,则必须明确设置 Module、Controller 和 Action。

请参阅示例 #4 Using routes下的Zend_Navigation 文档

注意:注意在页面中使用路由属性时,还要指定路由定义的默认参数(模块、控制器、动作等),否则isActive()方法将无法判断页面是否活跃。

如果您不使用路由,请提供有关您的代码的更多信息。


关于您的更新:

您的 Zend_Navigations 必须如下所示

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'
    ),
));

然后, isActive() 方法应该像预期的那样工作。

于 2011-06-16T21:23:45.320 回答
0

如果你没有指定模块、控制器和动作变量,你不能不幸地使用 isActive() 方法

于 2011-06-16T17:00:43.143 回答