【问题标题】:Cannot make Yii nested menu "active", with parameters无法使用参数使 Yii 嵌套菜单“激活”
【发布时间】:2015-08-07 08:31:41
【问题描述】:

所以我有一个嵌套的下拉菜单,使用 CMenu 小部件。

$this->widget('zii.widgets.CMenu', array(
   'activeCssClass' => 'active',
   'activateParents' => true,
   'items' => '
         ... (several menus)
      array('label' => 'Profil',
            'url' => array('/profile/profile'),
            'active' => Yii::app()->controller->id == 'profile' || Yii::app()->controller->action->id == 'profile' || Yii::app()->controller->action->id->params == 'id',
            'items' => array(
                  array('label' => 'Profil Saya', 'url' => array('/profile/profile&id='.Yii::app()->user->name),),
                  array('label' => 'Ubah Password', 'url' => array('/profile/password'),),
             ),
         ),
);

当我点击“Profil Saya”时,活动的css只能在“Profil”菜单上工作,而不是“Profil Saya”。 网址如下所示:

http://localhost/monev/index.php?r=profile/profile&id=safira

但我上面的代码似乎根本不起作用。

【问题讨论】:

    标签: php css yii


    【解决方案1】:

    这是因为在您的路线中添加了&id='.Yii::app()->user->name。因此,您可以使用itemOptions 添加活动类。这里是一个小例子。希望对您有所帮助:

    $this->widget('zii.widgets.CMenu', array(
        'activeCssClass' => 'active',
        'activateParents' => true,
        'items' =>
          //...
          array(
             'label' => 'Profil',
             'url' => array('/profile/profile'),
             'active' => Yii::app()->controller->id == 'profile' || Yii::app()->controller->action->id == 'profile' || Yii::app()->controller->action->id->params == 'id',
             'items' => array(
                 array(
                     'label' => 'Profil Saya',
                     'url' => array('/profile/profile&id='.Yii::app()->user->name),
                     'itemOptions' => array(
                         'class' => ((strpos($this->getRoute(), 'profile/profile') !== false) ? 'active' : null)
                     )
                 ),
                 array('label' => 'Ubah Password', 'url' => array('/profile/password'),),
             ),
          ),
        )
    );
    

    【讨论】:

      猜你喜欢
      • 2018-07-01
      • 2023-03-18
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      • 2014-06-17
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      相关资源
      最近更新 更多