routes.php 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. /**
  9. * The routes file is where you define your URL structure, which is an important part of the
  10. * [information architecture](http://en.wikipedia.org/wiki/Information_architecture) of your
  11. * application. Here, you can use _routes_ to match up URL pattern strings to a set of parameters,
  12. * usually including a controller and action to dispatch matching requests to. For more information,
  13. * see the `Router` and `Route` classes.
  14. *
  15. * @see lithium\net\http\Router
  16. * @see lithium\net\http\Route
  17. */
  18. use lithium\net\http\Router;
  19. use lithium\core\Environment;
  20. /**
  21. * With globalization enabled a localized route is configured by connecting a
  22. * continuation route. Once the route has been connected, all the other
  23. * application routes become localized and may now carry a locale.
  24. *
  25. * Requests to routes like `/en/posts/edit/1138` or `/fr/posts/edit/1138` will
  26. * carry a locale, while `/posts/edit/1138` keeps on working as it did before.
  27. */
  28. if ($locales = Environment::get('locales')) {
  29. $template = '/{:locale:' . join('|', array_keys($locales)) . '}/{:args}';
  30. Router::connect($template, array(), array('continue' => true));
  31. }
  32. /**
  33. * Here, we are connecting `'/'` (the base path) to controller called `'Pages'`,
  34. * its action called `view()`, and we pass a param to select the view file
  35. * to use (in this case, `/views/pages/home.html.php`; see `app\controllers\PagesController`
  36. * for details).
  37. *
  38. * @see app\controllers\PagesController
  39. */
  40. Router::connect('/json', 'Bench::json');
  41. /**
  42. * Connect the rest of `PagesController`'s URLs. This will route URLs like `/pages/about` to
  43. * `PagesController`, rendering `/views/pages/about.html.php` as a static page.
  44. */
  45. Router::connect('/db/{:queries}', array('Bench::db', 'queries' => 1));
  46. /**
  47. * Add the testing routes. These routes are only connected in non-production environments, and allow
  48. * browser-based access to the test suite for running unit and integration tests for the Lithium
  49. * core, as well as your own application and any other loaded plugins or frameworks. Browse to
  50. * [http://path/to/app/test](/test) to run tests.
  51. */
  52. if (!Environment::is('production')) {
  53. Router::connect('/test/{:args}', array('controller' => 'lithium\test\Controller'));
  54. Router::connect('/test', array('controller' => 'lithium\test\Controller'));
  55. }
  56. /**
  57. * ### Database object routes
  58. *
  59. * The routes below are used primarily for accessing database objects, where `{:id}` corresponds to
  60. * the primary key of the database object, and can be accessed in the controller as
  61. * `$this->request->id`.
  62. *
  63. * If you're using a relational database, such as MySQL, SQLite or Postgres, where the primary key
  64. * is an integer, uncomment the routes below to enable URLs like `/posts/edit/1138`,
  65. * `/posts/view/1138.json`, etc.
  66. */
  67. // Router::connect('/{:controller}/{:action}/{:id:\d+}.{:type}', array('id' => null));
  68. // Router::connect('/{:controller}/{:action}/{:id:\d+}');
  69. /**
  70. * If you're using a document-oriented database, such as CouchDB or MongoDB, or another type of
  71. * database which uses 24-character hexidecimal values as primary keys, uncomment the routes below.
  72. */
  73. // Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}.{:type}', array('id' => null));
  74. // Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}');
  75. /**
  76. * Finally, connect the default route. This route acts as a catch-all, intercepting requests in the
  77. * following forms:
  78. *
  79. * - `/foo/bar`: Routes to `FooController::bar()` with no parameters passed.
  80. * - `/foo/bar/param1/param2`: Routes to `FooController::bar('param1, 'param2')`.
  81. * - `/foo`: Routes to `FooController::index()`, since `'index'` is assumed to be the action if none
  82. * is otherwise specified.
  83. *
  84. * In almost all cases, custom routes should be added above this one, since route-matching works in
  85. * a top-down fashion.
  86. */
  87. Router::connect('/{:controller}/{:action}/{:args}');
  88. ?>