当前位置: 首页>>代码示例>>PHP>>正文


PHP Menu::isItemActive方法代码示例

本文整理汇总了PHP中yii\widgets\Menu::isItemActive方法的典型用法代码示例。如果您正苦于以下问题:PHP Menu::isItemActive方法的具体用法?PHP Menu::isItemActive怎么用?PHP Menu::isItemActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\widgets\Menu的用法示例。


在下文中一共展示了Menu::isItemActive方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: isItemActive

 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);
     }
 }
开发者ID:oakcms,项目名称:oakcms,代码行数:27,代码来源:Menu.php

示例2: isItemActive

 protected function isItemActive($item)
 {
     if (is_string($item['url'])) {
         return $item['url'] === Yii::$app->request->url;
     } else {
         return parent::isItemActive($item);
     }
 }
开发者ID:heartshare,项目名称:dotplant2,代码行数:8,代码来源:Menu.php

示例3: isItemActive

 /**
  * Checks whether a menu item is active.
  * 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.
  * @param array $item the menu item to be checked
  * @return boolean whether the menu item is active
  */
 protected function isItemActive($item)
 {
     if (isset($item['urlActive']) && is_array($item['urlActive'])) {
         foreach ($item['urlActive'] as $auxUrl) {
             $auxItem = $item;
             $auxItem['url'] = $auxUrl;
             if (parent::isItemActive($auxItem)) {
                 return true;
             }
         }
     }
     return parent::isItemActive($item);
 }
开发者ID:wartron,项目名称:yii2-widgets-urlactive,代码行数:23,代码来源:Menu.php

示例4: isItemActive

 /**
  * Checks whether a menu item is active.
  * 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.
  * @param array $item the menu item to be checked
  * @return boolean whether the menu item is active
  */
 protected function isItemActive($item)
 {
     $res = parent::isItemActive($item);
     if (!$res) {
         $preg = null;
         if (isset($item['preg']) && !empty($item['preg'])) {
             $preg = $item['preg'];
         } elseif (isset($item['url'])) {
             $preg = $item['url'] . ($item['url'] != '/' ? '/*' : '');
         }
         if (!empty($preg)) {
             $preg = '/^' . str_replace('*', '(.*?)', str_replace('/', '\\/', $preg)) . '$/is';
             $res = preg_match($preg, Yii::$app->request->url) || preg_match($preg, Yii::$app->request->url . '/');
         }
     }
     return $res;
 }
开发者ID:maddoger,项目名称:yii2-website,代码行数:27,代码来源:Menu.php

示例5: isItemActive

 /**
  * Checks whether a menu item is active.
  * 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.
  * @param array $item the menu item to be checked
  * @return boolean whether the menu item is active
  */
 protected function isItemActive($item)
 {
     $res = parent::isItemActive($item);
     if (!$res && isset($item['activeUrl'])) {
         if (is_array($item['activeUrl'])) {
             $route = $item['activeUrl'][0];
         } else {
             $route = $item['activeUrl'];
         }
         if ($route[0] !== '/' && Yii::$app->controller) {
             $route = Yii::$app->controller->module->getUniqueId() . '/' . $route;
         }
         $route = ltrim($route, '/');
         $preg = '/^' . str_replace('*', '(.*?)', str_replace('/', '\\/', $route)) . '$/is';
         $res = preg_match($preg, $this->route);
     }
     return $res;
 }
开发者ID:maddoger,项目名称:yii2-cms-admin,代码行数:28,代码来源:Menu.php

示例6: isItemActive

 /**
  * @param array $item
  * @return bool
  */
 protected function isItemActive($item)
 {
     return isset($item['scope']) ? in_array(\Yii::$app->controller->id, $item['scope']) : parent::isItemActive($item);
 }
开发者ID:vetoni,项目名称:toko,代码行数:8,代码来源:Menu.php

示例7: isItemActive

 /**
  * Checks whether a menu item is active.
  * This is true when the module/controller part of the current route matches module/controller part of the provided item.
  * Implemented to activate correct menu when editing record (because there is no menu pointing to these controller actions).
  *
  * @param array $item the menu item to be checked
  * @return boolean whether the menu item is active
  */
 protected function isItemActive($item)
 {
     if (parent::isItemActive($item)) {
         return true;
     }
     $route = Yii::$app->controller->getRoute();
     $route = substr($route, 0, strrpos($route, '/'));
     $menuRoute = trim($item['url'][0], '/');
     if (substr($menuRoute, 0, strrpos($menuRoute, '/')) === $route) {
         return true;
     }
     return false;
 }
开发者ID:bigbrush,项目名称:yii2-cmf,代码行数:21,代码来源:AdminMenu.php

示例8: isItemActive

 /**
  * @inheritdoc
  */
 protected function isItemActive($item)
 {
     if (isset($item['url']) && is_string($item['url']) && $item['url'] === Url::current()) {
         return true;
     } elseif (isset($item['url'])) {
         if (is_array($item['url'])) {
             $url = $item['url'][0];
         } else {
             $url = $item['url'];
         }
         $url = str_replace("/index", "", $url);
         if (strpos('/' . Yii::$app->request->pathInfo, $url) !== false) {
             return true;
         } else {
             return false;
         }
     } else {
         return parent::isItemActive($item);
     }
 }
开发者ID:oakcms,项目名称:oakcms,代码行数:23,代码来源:Menu.php


注:本文中的yii\widgets\Menu::isItemActive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。