我有一个主菜单栏,项目是:Emlpoyees,Work,Search ...(我的项目力量由Yii提供)
<div id="mainmenu">
<?php $this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>Yii::t('app','Home'), 'url'=>array('/site/index')),
array('label'=>Yii::t('app','Employees'), 'url'=>array('/hr/index')),
array('label'=>Yii::t('app','Work'), 'url'=>array('/work/index')),
array('label'=>Yii::t('app','About'), 'url'=>array('/site/page', 'view'=>'about')),
array('label'=>Yii::t('app','Contact'), 'url'=>array('/site/contact')),
array('label'=>Yii::t('app','Search'), 'url'=>array('/hr/search')),
array('label'=>Yii::t('app','User Access'), 'url'=>array('/rights'), 'visible'=>Yii::app()->user->name==='admin'),
array('label'=>Yii::t('app','Manager User'), 'url'=>array('/user'), 'visible'=>Yii::app()->user->name==='admin'),
array('label'=>Yii::t('app','Login'), 'url'=>array('/user/login'),'visible'=>Yii::app()->user->isGuest),
array('label'=>Yii::t('app','Logout').' ('.Yii::app()->user->name.')', 'url'=>array('/user/logout'), 'visible'=>!Yii::app()->user->isGuest),
))); ?>
</div><!-- mainmenu -->
Yii设置了一个活跃的&#34;在它上面,当我去链接时它工作,ex:index.php?r = hr / index,&#34; Hr&#34;将激活(更改背景颜色)。
#mainmenu ul li a:hover, #mainmenu ul li.active a
{
color: #FF6633;
background-color:#fff;
border-radius: 10px 0px 0px 0px;
}
但是我希望背景颜色在&#34; Hr&#34;当我去链接index.php时更改?r = hr / create,index.php?r = hr / manager,...请帮帮我! (对不起,我的英语不好:()
答案 0 :(得分:0)
CMenu的项目还有一个active
字段(布尔值),用于确定哪些菜单项应呈现为活动状态。 (有适当的CSS类。)
默认情况下,当当前控制器和操作都匹配时,此active
字段将计算为true
,但您可以使用自定义表达式轻松覆盖此字段,以仅考虑当前控制器:< / p>
<div id="mainmenu">
<?php $this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>Yii::t('app','Home'), 'url'=>array('/site/index')),
array('label'=>Yii::t('app','Employees'), 'url'=>array('/hr/index'),
'active'=>Yii::app()->controller->id=='hr'),
array('label'=>Yii::t('app','Work'), 'url'=>array('/work/index')),
array('label'=>Yii::t('app','About'), 'url'=>array('/site/page', 'view'=>'about')),
array('label'=>Yii::t('app','Contact'), 'url'=>array('/site/contact')),
array('label'=>Yii::t('app','Search'), 'url'=>array('/hr/search')),
array('label'=>Yii::t('app','User Access'), 'url'=>array('/rights'), 'visible'=>Yii::app()->user->name==='admin'),
array('label'=>Yii::t('app','Manager User'), 'url'=>array('/user'), 'visible'=>Yii::app()->user->name==='admin'),
array('label'=>Yii::t('app','Login'), 'url'=>array('/user/login'),'visible'=>Yii::app()->user->isGuest),
array('label'=>Yii::t('app','Logout').' ('.Yii::app()->user->name.')', 'url'=>array('/user/logout'), 'visible'=>!Yii::app()->user->isGuest),
))); ?>
</div><!-- mainmenu -->