我正在设置一个小页面,所以我从 URL 中删除了/site/。大多数页面将是站点 Controller 上的静态页面,因此这看起来更干净。
菜单小部件配置如下:
$menuItems = [
['label' => 'Home', 'url' => ['/']],
['label' => 'About', 'url' => ['/about']],
['label' => 'Projects', 'url' => ['/projects']],
];
配置规则是
'rules' => [
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<action:\w+>' => 'site/<action>',
],
现在我的问题是我的菜单项链接不再标记为事件(css
.active
)。是什么控制了这一点,我该如何改变它?
最佳答案
解决了。
像这样更改菜单项
$menuItems = [
['label' => 'Home', 'url' => ['/'], 'active' => $this->context->route == 'site/index'],
['label' => 'About', 'url' => ['/about'], 'active' => $this->context->route == 'site/about'],
['label' => 'Projects', 'url' => ['/projects'], 'active' => $this->context->route == 'site/projects'],
];
关于yii2 - 事件菜单项的控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35313526/