|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Routes configuration. |
| 4 | + * |
| 5 | + * In this file, you set up routes to your controllers and their actions. |
| 6 | + * Routes are very important mechanism that allows you to freely connect |
| 7 | + * different URLs to chosen controllers and their actions (functions). |
| 8 | + * |
| 9 | + * It's loaded within the context of `Application::routes()` method which |
| 10 | + * receives a `RouteBuilder` instance `$routes` as method argument. |
| 11 | + * |
| 12 | + * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) |
| 13 | + * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
| 14 | + * |
| 15 | + * Licensed under The MIT License |
| 16 | + * For full copyright and license information, please see the LICENSE.txt |
| 17 | + * Redistributions of files must retain the above copyright notice. |
| 18 | + * |
| 19 | + * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
| 20 | + * @link https://cakephp.org CakePHP(tm) Project |
| 21 | + * @license https://opensource.org/licenses/mit-license.php MIT License |
| 22 | + */ |
| 23 | + |
| 24 | +use Cake\Routing\Route\DashedRoute; |
| 25 | +use Cake\Routing\RouteBuilder; |
| 26 | + |
| 27 | +return function (RouteBuilder $routes): void { |
| 28 | + /* |
| 29 | + * The default class to use for all routes |
| 30 | + * |
| 31 | + * The following route classes are supplied with CakePHP and are appropriate |
| 32 | + * to set as the default: |
| 33 | + * |
| 34 | + * - Route |
| 35 | + * - InflectedRoute |
| 36 | + * - DashedRoute |
| 37 | + * |
| 38 | + * If no call is made to `Router::defaultRouteClass()`, the class used is |
| 39 | + * `Route` (`Cake\Routing\Route\Route`) |
| 40 | + * |
| 41 | + * Note that `Route` does not do any inflections on URLs which will result in |
| 42 | + * inconsistently cased URLs when used with `:plugin`, `:controller` and |
| 43 | + * `:action` markers. |
| 44 | + */ |
| 45 | + $routes->setRouteClass(DashedRoute::class); |
| 46 | + |
| 47 | + /* *** PHP-Frameworks-Bench *** */ |
| 48 | + $routes->connect('/hello/index', ['controller' => 'HelloWorld', 'action' => 'display', 'home']); |
| 49 | + |
| 50 | + $routes->scope('/', function (RouteBuilder $builder) { |
| 51 | + /* |
| 52 | + * Here, we are connecting '/' (base path) to a controller called 'Pages', |
| 53 | + * its action called 'display', and we pass a param to select the view file |
| 54 | + * to use (in this case, templates/Pages/home.php)... |
| 55 | + */ |
| 56 | + $builder->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); |
| 57 | + |
| 58 | + /* |
| 59 | + * ...and connect the rest of 'Pages' controller's URLs. |
| 60 | + */ |
| 61 | + $builder->connect('/pages/*', 'Pages::display'); |
| 62 | + |
| 63 | + /* |
| 64 | + * Connect catchall routes for all controllers. |
| 65 | + * |
| 66 | + * The `fallbacks` method is a shortcut for |
| 67 | + * |
| 68 | + * ``` |
| 69 | + * $builder->connect('/:controller', ['action' => 'index']); |
| 70 | + * $builder->connect('/:controller/:action/*', []); |
| 71 | + * ``` |
| 72 | + * |
| 73 | + * You can remove these routes once you've connected the |
| 74 | + * routes you want in your application. |
| 75 | + */ |
| 76 | + $builder->fallbacks(); |
| 77 | + }); |
| 78 | + |
| 79 | + /* |
| 80 | + * If you need a different set of middleware or none at all, |
| 81 | + * open new scope and define routes there. |
| 82 | + * |
| 83 | + * ``` |
| 84 | + * $routes->scope('/api', function (RouteBuilder $builder) { |
| 85 | + * // No $builder->applyMiddleware() here. |
| 86 | + * |
| 87 | + * // Parse specified extensions from URLs |
| 88 | + * // $builder->setExtensions(['json', 'xml']); |
| 89 | + * |
| 90 | + * // Connect API actions here. |
| 91 | + * }); |
| 92 | + * ``` |
| 93 | + */ |
| 94 | +}; |
0 commit comments