Yii 如何高亮当前标签
Yii how to highlight the current label
$this->breadcrumbs=array(
'Dailymarket Reports',
);
$this->menu=array(
array('label'=>'inbox', 'url'=>array('index')),
array('label'=>'sent', 'url'=>array('sent')),
);
上面我有两个标签。如果鼠标移出并选择 sent
作为活动标签,我希望 inbox
成为默认的活动标签。
如果要为指定项目添加 active
class:
$this->menu = array(
array(
'label' => 'inbox', 'url' => array('index'),
'active' => $this->action->id === 'index' ? true : null,
),
array(
'label' => 'sent', 'url' => array('sent'),
'active' => $this->action->id === 'sent' ? true : null,
),
);
您需要自己为 active
class 的项目设计样式。
您也可以忽略为当前项目指定 url
,因此它将显示为文本而不是 link:
$this->menu = array(
array(
'label' => 'inbox',
'url' => $this->action->id === 'index' ? null : array('index'),
),
array(
'label' => 'sent',
'url' => $this->action->id === 'sent' ? null : array('sent'),
),
);
我想你问的是如何显示根据当前路由选择的菜单项,如果你在Home
页面,那么应该选择Home
菜单项。
虽然您可以看到添加检查等解决方案,但如果您提供 link 的完整路径,则无需添加任何进一步的检查来激活菜单项,只需确保您没有通过 activateItems=>false
在layout文件的CMenu
widget里面,否则默认为true
,根据item的route设置是否匹配当前请求的route来决定是否自动激活item。
转到您要添加 menu
的视图,为您的 link 指定完整路径,例如 /controller/action
,例如,如果我有站点控制器的菜单 SiteController
操作我将提供如下路径。
$this->menu=array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'Demo', 'url'=>array('/site/demo')),
);
就是这样,如果您不需要为每个菜单项添加单独的检查,您就可以让它工作。
只要确保你有一个 css
class for li.active > a
这样你就可以得到突出显示的效果,
$this->breadcrumbs=array(
'Dailymarket Reports',
);
$this->menu=array(
array('label'=>'inbox', 'url'=>array('index')),
array('label'=>'sent', 'url'=>array('sent')),
);
上面我有两个标签。如果鼠标移出并选择 sent
作为活动标签,我希望 inbox
成为默认的活动标签。
如果要为指定项目添加 active
class:
$this->menu = array(
array(
'label' => 'inbox', 'url' => array('index'),
'active' => $this->action->id === 'index' ? true : null,
),
array(
'label' => 'sent', 'url' => array('sent'),
'active' => $this->action->id === 'sent' ? true : null,
),
);
您需要自己为 active
class 的项目设计样式。
您也可以忽略为当前项目指定 url
,因此它将显示为文本而不是 link:
$this->menu = array(
array(
'label' => 'inbox',
'url' => $this->action->id === 'index' ? null : array('index'),
),
array(
'label' => 'sent',
'url' => $this->action->id === 'sent' ? null : array('sent'),
),
);
我想你问的是如何显示根据当前路由选择的菜单项,如果你在Home
页面,那么应该选择Home
菜单项。
虽然您可以看到添加检查等解决方案,但如果您提供 link 的完整路径,则无需添加任何进一步的检查来激活菜单项,只需确保您没有通过 activateItems=>false
在layout文件的CMenu
widget里面,否则默认为true
,根据item的route设置是否匹配当前请求的route来决定是否自动激活item。
转到您要添加 menu
的视图,为您的 link 指定完整路径,例如 /controller/action
,例如,如果我有站点控制器的菜单 SiteController
操作我将提供如下路径。
$this->menu=array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'Demo', 'url'=>array('/site/demo')),
);
就是这样,如果您不需要为每个菜单项添加单独的检查,您就可以让它工作。
只要确保你有一个 css
class for li.active > a
这样你就可以得到突出显示的效果,