|
18 | 18 | * @license https://opensource.org/licenses/mit-license.php MIT License |
19 | 19 | */ |
20 | 20 |
|
21 | | -use Cake\Core\Plugin; |
| 21 | +use Cake\Http\Middleware\CsrfProtectionMiddleware; |
22 | 22 | use Cake\Routing\RouteBuilder; |
23 | 23 | use Cake\Routing\Router; |
24 | 24 | use Cake\Routing\Route\DashedRoute; |
|
43 | 43 | */ |
44 | 44 | Router::defaultRouteClass(DashedRoute::class); |
45 | 45 |
|
46 | | -// New route we're adding for our tagged action. |
47 | | -// The trailing `*` tells CakePHP that this action has |
48 | | -// passed parameters. |
49 | | -Router::scope( |
50 | | - '/articles', |
51 | | - ['controller' => 'Articles'], |
52 | | - function ($routes) { |
53 | | - $routes->connect('/tagged/*', ['action' => 'tags']); |
54 | | - } |
55 | | -); |
56 | | - |
57 | 46 | Router::scope('/', function (RouteBuilder $routes) { |
58 | | - /** |
59 | | - * Here, we are connecting '/' (base path) to a controller called 'Pages', |
60 | | - * its action called 'display', and we pass a param to select the view file |
61 | | - * to use (in this case, src/Template/Pages/home.ctp)... |
62 | | - */ |
| 47 | + // Register scoped middleware for in scopes. |
| 48 | + $routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([ |
| 49 | + 'httpOnly' => true |
| 50 | + ])); |
| 51 | + $routes->applyMiddleware('csrf'); |
63 | 52 | $routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); |
64 | | - |
65 | | - /** |
66 | | - * ...and connect the rest of 'Pages' controller's URLs. |
67 | | - */ |
68 | 53 | $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']); |
69 | 54 |
|
| 55 | + |
| 56 | + // New route we're adding for our tagged action. |
| 57 | + // The trailing `*` tells CakePHP that this action has |
| 58 | + // passed parameters. |
| 59 | + $routes->scope('/articles', function ($routes) { |
| 60 | + $routes->connect('/tagged/*', ['controller' => 'Articles', 'action' => 'tags']); |
| 61 | + }); |
| 62 | + |
70 | 63 | /** |
71 | 64 | * Connect catchall routes for all controllers. |
72 | | - * |
73 | | - * Using the argument `DashedRoute`, the `fallbacks` method is a shortcut for |
74 | | - * `$routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);` |
75 | | - * `$routes->connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);` |
76 | | - * |
77 | | - * Any route class can be used with this method, such as: |
78 | | - * - DashedRoute |
79 | | - * - InflectedRoute |
80 | | - * - Route |
81 | | - * - Or your own route class |
82 | | - * |
83 | | - * You can remove these routes once you've connected the |
84 | | - * routes you want in your application. |
85 | 65 | */ |
86 | 66 | $routes->fallbacks(DashedRoute::class); |
87 | 67 | }); |
88 | | - |
89 | | -/** |
90 | | - * Load all plugin routes. See the Plugin documentation on |
91 | | - * how to customize the loading of plugin routes. |
92 | | - */ |
93 | | -Plugin::routes(); |
0 commit comments