routes.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Default routes that CakePHP provides as catch all routes.
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package Cake.Config
  16. * @since CakePHP(tm) v 2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. /**
  20. * Connects the default, built-in routes, including prefix and plugin routes. The following routes are created
  21. * in the order below:
  22. *
  23. * For each of the Routing.prefixes the following routes are created. Routes containing `:plugin` are only
  24. * created when your application has one or more plugins.
  25. *
  26. * - `/:prefix/:plugin` a plugin shortcut route.
  27. * - `/:prefix/:plugin/:action/*` a plugin shortcut route.
  28. * - `/:prefix/:plugin/:controller`
  29. * - `/:prefix/:plugin/:controller/:action/*`
  30. * - `/:prefix/:controller`
  31. * - `/:prefix/:controller/:action/*`
  32. *
  33. * If plugins are found in your application the following routes are created:
  34. *
  35. * - `/:plugin` a plugin shortcut route.
  36. * - `/:plugin/:action/*` a plugin shortcut route.
  37. * - `/:plugin/:controller`
  38. * - `/:plugin/:controller/:action/*`
  39. *
  40. * And lastly the following catch-all routes are connected.
  41. *
  42. * - `/:controller'
  43. * - `/:controller/:action/*'
  44. *
  45. * You can disable the connection of default routes by deleting the require inside APP/Config/routes.php.
  46. */
  47. $prefixes = Router::prefixes();
  48. if ($plugins = CakePlugin::loaded()) {
  49. App::uses('PluginShortRoute', 'Routing/Route');
  50. foreach ($plugins as $key => $value) {
  51. $plugins[$key] = Inflector::underscore($value);
  52. }
  53. $pluginPattern = implode('|', $plugins);
  54. $match = array('plugin' => $pluginPattern);
  55. $shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern);
  56. foreach ($prefixes as $prefix) {
  57. $params = array('prefix' => $prefix, $prefix => true);
  58. $indexParams = $params + array('action' => 'index');
  59. Router::connect("/{$prefix}/:plugin", $indexParams, $shortParams);
  60. Router::connect("/{$prefix}/:plugin/:controller", $indexParams, $match);
  61. Router::connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match);
  62. }
  63. Router::connect('/:plugin', array('action' => 'index'), $shortParams);
  64. Router::connect('/:plugin/:controller', array('action' => 'index'), $match);
  65. Router::connect('/:plugin/:controller/:action/*', array(), $match);
  66. }
  67. foreach ($prefixes as $prefix) {
  68. $params = array('prefix' => $prefix, $prefix => true);
  69. $indexParams = $params + array('action' => 'index');
  70. Router::connect("/{$prefix}/:controller", $indexParams);
  71. Router::connect("/{$prefix}/:controller/:action/*", $params);
  72. }
  73. Router::connect('/:controller', array('action' => 'index'));
  74. Router::connect('/:controller/:action/*');
  75. $namedConfig = Router::namedConfig();
  76. if ($namedConfig['rules'] === false) {
  77. Router::connectNamed(true);
  78. }
  79. unset($namedConfig, $params, $indexParams, $prefix, $prefixes, $shortParams, $match,
  80. $pluginPattern, $plugins, $key, $value);