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


PHP Router::routes方法代码示例

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


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

示例1: main

 /**
  * @return void
  */
 public function main()
 {
     self::_loadRoutes();
     $formatter = "%15s  %-20s  %-20s  %-10s";
     $this->out(sprintf($formatter, 'Method', 'URI Pattern', 'Controller/Action', 'extensions'));
     foreach (Router::routes() as $route) {
         if (isset($route->defaults['_method'])) {
             if (is_array($route->defaults['_method'])) {
                 $outputMethod = implode(',', $route->defaults['_method']);
             } else {
                 $outputMethod = $route->defaults['_method'];
             }
         } else {
             $outputMethod = 'GET';
         }
         $uriPattern = $route->template;
         if (isset($route->options['_ext']) && $route->options['_ext']) {
             $ext = implode(',', $route->options['_ext']);
         } else {
             $ext = "none";
         }
         //そもそもControllerが定義されていないものに関しては表示しないようにしている。
         if (isset($route->defaults['controller'])) {
             $this->out(sprintf($formatter, $outputMethod, $uriPattern, $route->defaults['controller'] . '/' . $route->defaults['action'], $ext));
         }
     }
 }
开发者ID:webuilder240,项目名称:cake-console-routes,代码行数:30,代码来源:RoutesShell.php

示例2: check

 /**
  * Checks a url for the route that will be applied.
  *
  * @param string $url The URL to parse
  * @return null|false
  */
 public function check($url)
 {
     try {
         $route = Router::parse($url);
         foreach (Router::routes() as $r) {
             if ($r->match($route)) {
                 $name = isset($r->options['_name']) ? $r->options['_name'] : $r->getName();
                 break;
             }
         }
         $output = [['Route name', 'URI template', 'Defaults'], [$name, $url, json_encode($route)]];
         $this->helper('table')->output($output);
         $this->out();
     } catch (MissingRouteException $e) {
         $this->err("<warning>'{$url}' did not match any routes.</warning>");
         $this->out();
         return false;
     }
 }
开发者ID:CakeDC,项目名称:cakephp,代码行数:25,代码来源:RoutesShell.php

示例3: summary

 /**
  * Get summary data for the routes panel.
  *
  * @return int
  */
 public function summary()
 {
     return count(Router::routes());
 }
开发者ID:cakephp,项目名称:debug_kit,代码行数:9,代码来源:RoutesPanel.php

示例4: setupBeforeClass

 public static function setupBeforeClass()
 {
     static::$routes = Router::routes();
 }
开发者ID:bostontrader,项目名称:acctwerx,代码行数:4,代码来源:RequestErrors.php

示例5: testRedirectWithAnotherRouteClass

 /**
  * Test that redirect() works with another route class.
  *
  * @return void
  */
 public function testRedirectWithAnotherRouteClass()
 {
     $route1 = $this->getMockBuilder('Cake\\Routing\\Route\\RedirectRoute')->setConstructorArgs(['/mobile\''])->getMock();
     $class = '\\' . get_class($route1);
     Router::redirect('/mobile', '/', ['status' => 301, 'routeClass' => $class]);
     $routes = Router::routes();
     $route = $routes[0];
     $this->assertInstanceOf($class, $route);
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:14,代码来源:RouterTest.php

示例6: _router

 /**
  * Get urls from Router
  */
 protected function _router()
 {
     // go through each defined route
     foreach (Router::routes() as $route) {
         // not supposed to be in sitemap? exclude
         if (!isset($route->options['sitemap'])) {
             continue;
         }
         // defaults
         $changefreq = isset($route->options['sitemap']['frequency']) ? $route->options['sitemap']['frequency'] : 'monthly';
         $priority = isset($route->options['sitemap']['priority']) ? $route->options['sitemap']['priority'] : '0.6';
         // dynamic? execute callback if it exists
         if (strpos($route->template, '*') !== false || strpos($route->template, ':slug') !== false) {
             $callback = $this->_callback($route, true);
             if ($callback) {
                 if (is_array($callback)) {
                     foreach ($callback as $item) {
                         $this->_url[] = ['loc' => $item['url'], 'lastmod' => $item['modified'], 'changefreq' => $changefreq, 'priority' => $priority];
                     }
                 }
             }
             // ignore "/*"
             continue;
         }
         // in exclude array?
         if (in_array($route->template, $this->exclude)) {
             continue;
         }
         // calculate lastmod
         if (isset($route->options['sitemap']['modified'])) {
             switch ($route->options['sitemap']['modified']) {
                 case 'callback':
                     $lastmod = $this->_callback($route);
                     break;
                 case 'ctrl':
                     $lastmod = $this->_ctrl($route);
                     break;
                 default:
                     $lastmod = $route->options['sitemap']['modified'];
             }
         } else {
             $lastmod = $this->_file($route);
         }
         $lastmod = (new Time($lastmod ?: time()))->timezone(date_default_timezone_get())->toAtomString();
         // add record
         $this->_url[] = ['loc' => Router::url($route->template, true), 'lastmod' => $lastmod, 'changefreq' => $changefreq, 'priority' => $priority];
     }
 }
开发者ID:unimatrix,项目名称:cakephp-utility,代码行数:51,代码来源:SitemapComponent.php

示例7: testRedirect

 /**
  * Test that redirect() works.
  *
  * @return void
  */
 public function testRedirect()
 {
     Router::redirect('/mobile', '/', ['status' => 301]);
     $routes = Router::routes();
     $route = $routes[0];
     $this->assertInstanceOf('Cake\\Routing\\Route\\RedirectRoute', $route);
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:12,代码来源:RouterTest.php

示例8: _buildPrefixes

 /**
  * Build prefixes for App and Plugins based on configured routes
  *
  * @return void
  */
 protected function _buildPrefixes()
 {
     $routes = Router::routes();
     foreach ($routes as $key => $route) {
         if (isset($route->defaults['prefix'])) {
             $prefix = Inflector::camelize($route->defaults['prefix']);
             if (!isset($route->defaults['plugin'])) {
                 $this->prefixes[$prefix] = true;
             } else {
                 $this->pluginPrefixes[$route->defaults['plugin']][$prefix] = true;
             }
         }
     }
 }
开发者ID:cakephp,项目名称:acl,代码行数:19,代码来源:AclExtras.php

示例9: setRoutes

 public function setRoutes()
 {
     $routes_info = array();
     $all_routes = Router::routes();
     $ignore = array('index\\');
     foreach ($all_routes as $route) {
         $reflection = implode('\\', $route->defaults);
         if (!in_array($reflection, $ignore)) {
             $routes_info[$route->template] = json_encode($route->defaults);
             $routes[$route->template] = $reflection . ' -> ' . $route->template;
         }
     }
     $this->controller->set('routes', $routes);
     $this->controller->set('routes_info', $routes_info);
 }
开发者ID:markhatchell,项目名称:cakephp3-easy-menus,代码行数:15,代码来源:EasyMenusComComponent.php

示例10: _routerPrefixes

 /**
  * Gets a CamelizedList of all existing router prefixes.
  *
  * @return array
  */
 protected function _routerPrefixes()
 {
     $cache = static::cache('_routerPrefixes');
     if (!$cache) {
         $prefixes = [];
         foreach (Router::routes() as $route) {
             if (empty($route->defaults['prefix'])) {
                 continue;
             } else {
                 $prefix = Inflector::camelize($route->defaults['prefix']);
                 if (!in_array($prefix, $prefixes)) {
                     $prefixes[] = $prefix;
                 }
             }
         }
         $cache = static::cache('_routerPrefixes', $prefixes);
     }
     return $cache;
 }
开发者ID:quickapps-plugins,项目名称:user,代码行数:24,代码来源:AcoManager.php


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