From 07a04c526e4a724a3378a3ad0ee66b0bc50e6fbd Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 12 Aug 2013 14:11:46 -0400 Subject: [PATCH] Fixed Menu active item check. --- framework/yii/bootstrap/Nav.php | 9 ++++++++- framework/yii/widgets/Menu.php | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/framework/yii/bootstrap/Nav.php b/framework/yii/bootstrap/Nav.php index 38451d1..186c20a 100644 --- a/framework/yii/bootstrap/Nav.php +++ b/framework/yii/bootstrap/Nav.php @@ -190,7 +190,14 @@ class Nav extends Widget */ protected function isItemActive($item) { - if (isset($item['url']) && is_array($item['url']) && trim($item['url'][0], '/') === $this->route) { + if (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) { + $route = $item['url'][0]; + if ($route[0] !== '/' && Yii::$app->controller) { + $route = Yii::$app->controller->module->getUniqueId() . '/' . $route; + } + if (ltrim($route, '/') !== $this->route) { + return false; + } unset($item['url']['#']); if (count($item['url']) > 1) { foreach (array_splice($item['url'], 1) as $name => $value) { diff --git a/framework/yii/widgets/Menu.php b/framework/yii/widgets/Menu.php index 40fd479..1d36460 100644 --- a/framework/yii/widgets/Menu.php +++ b/framework/yii/widgets/Menu.php @@ -284,7 +284,14 @@ class Menu extends Widget */ protected function isItemActive($item) { - if (isset($item['url']) && is_array($item['url']) && trim($item['url'][0], '/') === $this->route) { + if (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) { + $route = $item['url'][0]; + if ($route[0] !== '/' && Yii::$app->controller) { + $route = Yii::$app->controller->module->getUniqueId() . '/' . $route; + } + if (ltrim($route, '/') !== $this->route) { + return false; + } unset($item['url']['#']); if (count($item['url']) > 1) { foreach (array_splice($item['url'], 1) as $name => $value) {