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


PHP route::current方法代码示例

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


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

示例1: __getMenu

 /**
  * @brief 获取到商家中心的导航菜单和左边栏菜单
  *
  * @return array $res
  */
 private function __getMenu()
 {
     $currentPermission = shopAuth::getSellerPermission();
     $defaultActionName = route::current()->getActionName();
     $shopMenu = config::get('shop');
     $shortcutMenuAction = $this->getShortcutMenu();
     $sidebar['commonUser']['label'] = '常用菜单';
     $sidebar['commonUser']['shortcutMenu'] = true;
     $sidebar['commonUser']['active'] = true;
     //是否展开
     $sidebar['commonUser']['icon'] = 'glyphicon glyphicon-heart';
     //$sidebar['commonUser']['menu'] = $commonUserMenu;
     foreach ((array) $shopMenu as $menu => $row) {
         if ($row['display'] === false) {
             continue;
         }
         foreach ((array) $row['menu'] as $k => $params) {
             //编辑常用菜单使用
             if ($params['display'] !== false && (!$currentPermission || in_array($params['as'], $currentPermission))) {
                 $allMenu[$menu]['label'] = $row['label'];
                 if (in_array($params['action'], $shortcutMenuAction)) {
                     $sidebar['commonUser']['menu'][] = $params;
                     $params['isShortcutMenu'] = true;
                 }
                 $allMenu[$menu]['menu'][] = $params;
             }
             if ($row['shopIndex'] || !$currentPermission || $params['display'] && in_array($params['as'], $currentPermission)) {
                 if (!$navbar[$menu]) {
                     $navbar[$menu]['label'] = $row['label'];
                     $navbar[$menu]['icon'] = $row['icon'];
                     $navbar[$menu]['action'] = $navbar[$menu]['action'] ? $navbar[$menu]['action'] : $params['action'];
                     $navbar[$menu]['default'] = false;
                 }
             }
             //如果为当前的路由则高亮
             if (!$navbar[$menu]['default'] && $params['action'] == $defaultActionName && $navbar[$menu]) {
                 $navbar[$menu]['default'] = true;
                 $selectMenu = $menu;
             }
         }
         if (!$row['shopIndex'] && $selectMenu == $menu) {
             foreach ((array) $row['menu'] as $k => $params) {
                 $sidebar[$menu]['active'] = true;
                 $sidebar[$menu]['label'] = $row['label'];
                 $sidebar[$menu]['icon'] = $row['icon'];
                 if (!$currentPermission || in_array($params['as'], $currentPermission)) {
                     $params['default'] = $params['action'] == $defaultActionName ? true : false;
                     $sidebar[$menu]['menu'][] = $params;
                 }
             }
         }
     }
     $res['all'] = $allMenu;
     $res['navbar'] = $navbar;
     $res['sidebar'] = $sidebar;
     return $res;
 }
开发者ID:453111208,项目名称:bbc,代码行数:62,代码来源:controller.php

示例2: get

 public static function get($url)
 {
     $url = preg_replace('/^(\\/)/', '', $url);
     $new_url = $url;
     // REST API
     if (preg_match('/\\.([\\-_a-zA-Z]+)$/', $new_url)) {
         $split = explode('.', $new_url);
         api::set(array_pop($split));
         $new_url = implode('.', $split);
     }
     // Static routes
     if (!empty(self::$route[$url])) {
         $new_url = self::$route[$url];
     }
     // Regex routes
     $route_keys = array_keys(self::$route);
     foreach ($route_keys as $okey) {
         $key = '/^' . str_replace('/', '\\/', $okey) . '$/';
         if (preg_match($key, $url)) {
             if (!is_array(self::$route[$okey])) {
                 $new_url = preg_replace($key, self::$route[$okey], $url);
             } else {
                 /* Run regex replace on keys */
                 $new_url = self::$route[$okey];
                 // Controller
                 if (isset($new_url['controller'])) {
                     $new_url['controller'] = preg_replace($key, $new_url['controller'], $url);
                 }
                 // Function
                 if (isset($new_url['function'])) {
                     $new_url['function'] = preg_replace($key, $new_url['function'], $url);
                 }
                 // Arguments
                 if (isset($new_url['arguments'])) {
                     $x = 0;
                     while (isset($new_url['arguments'][$x])) {
                         $new_url['arguments'][$x] = preg_replace($key, $new_url['arguments'][$x], $url);
                         $x += 1;
                     }
                 }
             }
         }
     }
     // If URL is empty use default route
     if (empty($new_url) or $new_url == '/') {
         $new_url = self::$route['default_route'];
     }
     // Turn into array
     if (!is_array($new_url)) {
         // Remove the /index.php/ at the beginning
         //$new_url = preg_replace('/^(\/)/','',$url);
         $tmp_url = explode('/', $new_url);
         $new_url = array('controller' => $tmp_url[0], 'function' => 'index', 'arguments' => array(), 'string' => $new_url, 'segments' => $tmp_url);
         // Function
         if (!empty($tmp_url[1])) {
             $new_url['function'] = $tmp_url[1];
         }
         // Arguments
         $x = 2;
         while (isset($tmp_url[$x])) {
             $new_url['arguments'][] = $tmp_url[$x];
             $x += 1;
         }
     } else {
         // Add missing keys
         if (!isset($new_url['function'])) {
             $new_url['function'] = 'index';
         }
         if (!isset($new_url['arguments'])) {
             $new_url['arguments'] = array();
         }
         // Build string key for URL array
         // Controller
         $s = $new_url['controller'];
         // Function
         if (isset($new_url['function'])) {
             $s .= "/{$new_url['function']}";
         }
         // Arguments
         foreach ($new_url['arguments'] as $arg) {
             $s .= "/{$arg}";
         }
         $new_url['string'] = $s;
         // Add segments key
         $new_url['segments'] = explode('/', $new_url['string']);
     }
     // Controller class
     $new_url['controller_class'] = explode('/', $new_url['controller']);
     $new_url['controller_class'] = end($new_url['controller_class']);
     self::$current = $new_url;
     return $new_url;
 }
开发者ID:reang,项目名称:Dingo-Framework,代码行数:92,代码来源:route.php


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