|
24 | 24 | use Cake\Routing\Route\DashedRoute; |
25 | 25 | use Cake\Routing\RouteBuilder; |
26 | 26 |
|
27 | | -/* |
28 | | - * The default class to use for all routes |
29 | | - * |
30 | | - * The following route classes are supplied with CakePHP and are appropriate |
31 | | - * to set as the default: |
32 | | - * |
33 | | - * - Route |
34 | | - * - InflectedRoute |
35 | | - * - DashedRoute |
36 | | - * |
37 | | - * If no call is made to `Router::defaultRouteClass()`, the class used is |
38 | | - * `Route` (`Cake\Routing\Route\Route`) |
39 | | - * |
40 | | - * Note that `Route` does not do any inflections on URLs which will result in |
41 | | - * inconsistently cased URLs when used with `:plugin`, `:controller` and |
42 | | - * `:action` markers. |
43 | | - */ |
44 | | -/** @var \Cake\Routing\RouteBuilder $routes */ |
45 | | -$routes->setRouteClass(DashedRoute::class); |
46 | | - |
47 | | -$routes->scope('/', function (RouteBuilder $builder) { |
| 27 | +return static function (RouteBuilder $routes) { |
48 | 28 | /* |
49 | | - * Here, we are connecting '/' (base path) to a controller called 'Pages', |
50 | | - * its action called 'display', and we pass a param to select the view file |
51 | | - * to use (in this case, templates/Pages/home.php)... |
| 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. |
52 | 44 | */ |
53 | | - $builder->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); |
| 45 | + $routes->setRouteClass(DashedRoute::class); |
54 | 46 |
|
55 | | - /* |
56 | | - * ...and connect the rest of 'Pages' controller's URLs. |
57 | | - */ |
58 | | - $builder->connect('/pages/*', 'Pages::display'); |
| 47 | + $routes->scope('/', function (RouteBuilder $builder) { |
| 48 | + /* |
| 49 | + * Here, we are connecting '/' (base path) to a controller called 'Pages', |
| 50 | + * its action called 'display', and we pass a param to select the view file |
| 51 | + * to use (in this case, templates/Pages/home.php)... |
| 52 | + */ |
| 53 | + $builder->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); |
| 54 | + |
| 55 | + /* |
| 56 | + * ...and connect the rest of 'Pages' controller's URLs. |
| 57 | + */ |
| 58 | + $builder->connect('/pages/*', 'Pages::display'); |
| 59 | + |
| 60 | + /* |
| 61 | + * Connect catchall routes for all controllers. |
| 62 | + * |
| 63 | + * The `fallbacks` method is a shortcut for |
| 64 | + * |
| 65 | + * ``` |
| 66 | + * $builder->connect('/:controller', ['action' => 'index']); |
| 67 | + * $builder->connect('/:controller/:action/*', []); |
| 68 | + * ``` |
| 69 | + * |
| 70 | + * You can remove these routes once you've connected the |
| 71 | + * routes you want in your application. |
| 72 | + */ |
| 73 | + $builder->fallbacks(); |
| 74 | + }); |
59 | 75 |
|
60 | 76 | /* |
61 | | - * Connect catchall routes for all controllers. |
| 77 | + * If you need a different set of middleware or none at all, |
| 78 | + * open new scope and define routes there. |
62 | 79 | * |
63 | | - * The `fallbacks` method is a shortcut for |
64 | | - * |
65 | | - * ``` |
66 | | - * $builder->connect('/{controller}', ['action' => 'index']); |
67 | | - * $builder->connect('/{controller}/{action}/*', []); |
68 | 80 | * ``` |
| 81 | + * $routes->scope('/api', function (RouteBuilder $builder) { |
| 82 | + * // No $builder->applyMiddleware() here. |
69 | 83 | * |
70 | | - * You can remove these routes once you've connected the |
71 | | - * routes you want in your application. |
| 84 | + * // Parse specified extensions from URLs |
| 85 | + * // $builder->setExtensions(['json', 'xml']); |
| 86 | + * |
| 87 | + * // Connect API actions here. |
| 88 | + * }); |
| 89 | + * ``` |
72 | 90 | */ |
73 | | - $builder->fallbacks(); |
74 | | -}); |
75 | | - |
76 | | -/* |
77 | | - * If you need a different set of middleware or none at all, |
78 | | - * open new scope and define routes there. |
79 | | - * |
80 | | - * ``` |
81 | | - * $routes->scope('/api', function (RouteBuilder $builder) { |
82 | | - * // No $builder->applyMiddleware() here. |
83 | | - * |
84 | | - * // Parse specified extensions from URLs |
85 | | - * // $builder->setExtensions(['json', 'xml']); |
86 | | - * |
87 | | - * // Connect API actions here. |
88 | | - * }); |
89 | | - * ``` |
90 | | - */ |
| 91 | +}; |
0 commit comments