CMenu - 活动类未呈现 [英] CMenu - active class not rendering

查看:18
本文介绍了CMenu - 活动类未呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'items'=>array(
     array(
         'label'=>'About',
         'url'=>array('about/index')
),

about/index - 我们得到菜单上的类 - 活动.

about/index - we get the class on the menu - active.

about/graphic - 我们没有激活菜单上的类.

about/graphic - we don't get the class on the menu active.

about/print - 我们没有激活菜单上的类.

about/print - we don't get the class on the menu active.

请注意,菜单没有子项.仅关于.

Please note that the menu has NO subitems. Only About.

无论用户是使用图形、印刷品还是其他内容,我们都希望突出显示关于.

No mater if the user is on graphic, print or whatever, we wish to have the About highlighted.

我们如何才能做到这一点?

How can we accomplish this ?

我多次尝试编辑该url"参数.没有运气.

I've tried to edit that 'url' param a lot. No luck.

推荐答案

'items'=>array(
     array(
         'label'=>'About',
         'url'=>array('about/index'),
         'active'=>Yii::app()->controller->id=='about',
),

添加了 active 参数.这奏效了.

Added the active param. This worked.

active:布尔值,可选,该菜单项是否处于活动状态(当前选中).如果菜单项处于活动状态而 activeClass 未处于活动状态为空,其 CSS 类将附加 activeClass.如果这个选项未设置时,菜单项将自动设置为活动状态当前请求由 url 触发. 注意 GET 参数'url' 选项中未指定的将被忽略.

active: boolean, optional, whether this menu item is in active state (currently selected). If a menu item is active and activeClass is not empty, its CSS class will be appended with activeClass. If this option is not set, the menu item will be set active automatically when the current request is triggered by url. Note that the GET parameters not specified in the 'url' option will be ignored.

我已经设置了那个属性.否则它不会工作.

I've set that property. Otherwise it wouldn't work.

但是,正如您在粗线中看到的那样,他们说这应该是自动触发的.不是这个案子.

However, as you can see on the bold line, they say this should be automatically triggered. It wasn't on this case.

我想这是因为 Yii 期待 About 的子元素以便应用该类,因为有任何,我们必须强制它,而不是获取父元素.

I suppose this was the case due to the fact that Yii is expecting a child element of About in order to apply that class, since there's any, we have to force it, to get the parent instead.

不过不确定.

这篇关于CMenu - 活动类未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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