Yii如何突出显示当前菜单项 [英] Yii how to highlight the current menu item

查看:43
本文介绍了Yii如何突出显示当前菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码显示菜单项.

I used the following code to display the menu items.

默认情况下,主页"链接应处于激活状态.这样我就使用了代码

Here by default the 'Home' link should be activated. So that i used the code

active' => $this->id =='default' ? true : false

$this->widget('zii.widgets.CMenu',array(
     'linkLabelWrapper' => 'span',
    'items'=>array(
    array('label'=>'Home', 'url'=>array('post/index'),'active'=>$this->id=='default'?true:false),
    array('label'=>'About', 'url'=>array('site/page', 'view'=>'about'),'active'=>$this->id=='about'?true:false),
    array('label'=>'Test', 'url'=>array('site/page', 'view'=>'test')),
    array('label'=>'Contact', 'url'=>array('site/contact')),
    array('label'=>'Login', 'url'=>array('site/login'), 'visible'=>Yii::app()->user->isGuest),
    array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('site/logout'), 'visible'=>!Yii::app()->user->isGuest)
    ),
    )); 

我引用了网址 http://www.yiiframework.com/doc/api/1.1/CMenu#activateItems-detail 但是我不知道如何使用这些参数.请帮助

I referred the url http://www.yiiframework.com/doc/api/1.1/CMenu#activateItems-detail But i dont know how to use these parameters. Please help

推荐答案

不是Yii方式,而是(更简单的)jQuery方式:

Not the Yii way, but the (simpler) jQuery way:

// find menu-item associated with this page and make current:
$('a').each(function(index, value) { 
    if ($(this).prop("href") === window.location.href) {
        $(this).addClass("current-page");
    } 
});

这篇关于Yii如何突出显示当前菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆