yii\widgets\Menu::isItemActive PHP 메소드

isItemActive() 보호된 메소드

This is done by checking if [[route]] and [[params]] match that specified in the url option of the menu item. When the url option of a menu item is specified in terms of an array, its first element is treated as the route for the item and the rest of the elements are the associated parameters. Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item be considered active.
protected isItemActive ( array $item ) : boolean
$item array the menu item to be checked
리턴 boolean whether the menu item is active
    protected function isItemActive($item)
    {
        if (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) {
            $route = Yii::getAlias($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) {
                $params = $item['url'];
                unset($params[0]);
                foreach ($params as $name => $value) {
                    if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
                        return false;
                    }
                }
            }
            return true;
        }
        return false;
    }

Usage Example

예제 #1
0
파일: Menu.php 프로젝트: oakcms/oakcms
 protected function isItemActive($item)
 {
     if ($item['url'] == Url::to('')) {
         return true;
     } elseif (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) {
             $params = $item['url'];
             unset($params[0]);
             foreach ($params as $name => $value) {
                 if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
                     return false;
                 }
             }
         }
         return true;
     } else {
         return parent::isItemActive($item);
     }
 }
All Usage Examples Of yii\widgets\Menu::isItemActive