質問編集履歴

2

エラー詳細等を記載しました

2018/12/21 14:56

投稿

nori-p
nori-p

スコア13

test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,9 @@
18
18
 
19
19
  ```
20
20
 
21
- CSRF token mismatch
21
+ CSRF token mismatch.
22
+
23
+ Cake\Http\Exception\InvalidCsrfTokenException
22
24
 
23
25
  ```
24
26
 

1

遅くなり申し訳ありません。追記しました。

2018/12/21 14:56

投稿

nori-p
nori-p

スコア13

test CHANGED
File without changes
test CHANGED
@@ -74,6 +74,414 @@
74
74
 
75
75
 
76
76
 
77
+ src/Application.php
78
+
79
+ ```PHP
80
+
81
+ <?php
82
+
83
+ /**
84
+
85
+ * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
86
+
87
+ * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
88
+
89
+ *
90
+
91
+ * Licensed under The MIT License
92
+
93
+ * For full copyright and license information, please see the LICENSE.txt
94
+
95
+ * Redistributions of files must retain the above copyright notice.
96
+
97
+ *
98
+
99
+ * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
100
+
101
+ * @link https://cakephp.org CakePHP(tm) Project
102
+
103
+ * @since 3.3.0
104
+
105
+ * @license https://opensource.org/licenses/mit-license.php MIT License
106
+
107
+ */
108
+
109
+ namespace App;
110
+
111
+
112
+
113
+ use Cake\Core\Configure;
114
+
115
+ use Cake\Core\Exception\MissingPluginException;
116
+
117
+ use Cake\Error\Middleware\ErrorHandlerMiddleware;
118
+
119
+ use Cake\Http\BaseApplication;
120
+
121
+ use Cake\Http\Middleware\CsrfProtectionMiddleware;
122
+
123
+ use Cake\Routing\Middleware\AssetMiddleware;
124
+
125
+ use Cake\Routing\Middleware\RoutingMiddleware;
126
+
127
+
128
+
129
+ /**
130
+
131
+ * Application setup class.
132
+
133
+ *
134
+
135
+ * This defines the bootstrapping logic and middleware layers you
136
+
137
+ * want to use in your application.
138
+
139
+ */
140
+
141
+ class Application extends BaseApplication
142
+
143
+ {
144
+
145
+ /**
146
+
147
+ * {@inheritDoc}
148
+
149
+ */
150
+
151
+ public function bootstrap()
152
+
153
+ {
154
+
155
+ // Call parent to load bootstrap from files.
156
+
157
+ parent::bootstrap();
158
+
159
+
160
+
161
+ if (PHP_SAPI === 'cli') {
162
+
163
+ try {
164
+
165
+ $this->addPlugin('Bake');
166
+
167
+ } catch (MissingPluginException $e) {
168
+
169
+ // Do not halt if the plugin is missing
170
+
171
+ }
172
+
173
+
174
+
175
+ $this->addPlugin('Migrations');
176
+
177
+ }
178
+
179
+
180
+
181
+ /*
182
+
183
+ * Only try to load DebugKit in development mode
184
+
185
+ * Debug Kit should not be installed on a production system
186
+
187
+ */
188
+
189
+ if (Configure::read('debug')) {
190
+
191
+ $this->addPlugin(\DebugKit\Plugin::class);
192
+
193
+ }
194
+
195
+ }
196
+
197
+
198
+
199
+ /**
200
+
201
+ * Setup the middleware queue your application will use.
202
+
203
+ *
204
+
205
+ * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup.
206
+
207
+ * @return \Cake\Http\MiddlewareQueue The updated middleware queue.
208
+
209
+ */
210
+
211
+ public function middleware($middlewareQueue)
212
+
213
+ {
214
+
215
+ $middlewareQueue
216
+
217
+ // Catch any exceptions in the lower layers,
218
+
219
+ // and make an error page/response
220
+
221
+ ->add(ErrorHandlerMiddleware::class)
222
+
223
+
224
+
225
+ // Handle plugin/theme assets like CakePHP normally does.
226
+
227
+ ->add(new AssetMiddleware([
228
+
229
+ 'cacheTime' => Configure::read('Asset.cacheTime')
230
+
231
+ ]))
232
+
233
+
234
+
235
+ // Add routing middleware.
236
+
237
+ // Routes collection cache enabled by default, to disable route caching
238
+
239
+ // pass null as cacheConfig, example: `new RoutingMiddleware($this)`
240
+
241
+ // you might want to disable this cache in case your routing is extremely simple
242
+
243
+ ->add(new RoutingMiddleware($this, '_cake_routes_'))
244
+
245
+
246
+
247
+ // Add csrf middleware.
248
+
249
+ ->add(new CsrfProtectionMiddleware([
250
+
251
+ 'httpOnly' => true
252
+
253
+ ]));
254
+
255
+ return $middlewareQueue;
256
+
257
+ }
258
+
259
+ }
260
+
261
+
262
+
263
+ ```
264
+
265
+
266
+
267
+ config/routes.php
268
+
269
+ ```PHP
270
+
271
+ <?php
272
+
273
+ /**
274
+
275
+ * Routes configuration
276
+
277
+ *
278
+
279
+ * In this file, you set up routes to your controllers and their actions.
280
+
281
+ * Routes are very important mechanism that allows you to freely connect
282
+
283
+ * different URLs to chosen controllers and their actions (functions).
284
+
285
+ *
286
+
287
+ * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
288
+
289
+ * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
290
+
291
+ *
292
+
293
+ * Licensed under The MIT License
294
+
295
+ * For full copyright and license information, please see the LICENSE.txt
296
+
297
+ * Redistributions of files must retain the above copyright notice.
298
+
299
+ *
300
+
301
+ * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
302
+
303
+ * @link https://cakephp.org CakePHP(tm) Project
304
+
305
+ * @license https://opensource.org/licenses/mit-license.php MIT License
306
+
307
+ */
308
+
309
+ use Cake\Http\Middleware\CsrfProtectionMiddleware;
310
+
311
+ use Cake\Routing\RouteBuilder;
312
+
313
+ use Cake\Routing\Router;
314
+
315
+ use Cake\Routing\Route\DashedRoute;
316
+
317
+
318
+
319
+ /**
320
+
321
+ * The default class to use for all routes
322
+
323
+ *
324
+
325
+ * The following route classes are supplied with CakePHP and are appropriate
326
+
327
+ * to set as the default:
328
+
329
+ *
330
+
331
+ * - Route
332
+
333
+ * - InflectedRoute
334
+
335
+ * - DashedRoute
336
+
337
+ *
338
+
339
+ * If no call is made to `Router::defaultRouteClass()`, the class used is
340
+
341
+ * `Route` (`Cake\Routing\Route\Route`)
342
+
343
+ *
344
+
345
+ * Note that `Route` does not do any inflections on URLs which will result in
346
+
347
+ * inconsistently cased URLs when used with `:plugin`, `:controller` and
348
+
349
+ * `:action` markers.
350
+
351
+ *
352
+
353
+ * Cache: Routes are cached to improve performance, check the RoutingMiddleware
354
+
355
+ * constructor in your `src/Application.php` file to change this behavior.
356
+
357
+ *
358
+
359
+ */
360
+
361
+ Router::defaultRouteClass(DashedRoute::class);
362
+
363
+
364
+
365
+ Router::scope('/', function (RouteBuilder $routes) {
366
+
367
+ // Register scoped middleware for in scopes.
368
+
369
+ $routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([
370
+
371
+ 'httpOnly' => true
372
+
373
+ ]));
374
+
375
+
376
+
377
+ /**
378
+
379
+ * Apply a middleware to the current route scope.
380
+
381
+ * Requires middleware to be registered via `Application::routes()` with `registerMiddleware()`
382
+
383
+ */
384
+
385
+ $routes->applyMiddleware('csrf');
386
+
387
+
388
+
389
+ /**
390
+
391
+ * Here, we are connecting '/' (base path) to a controller called 'Pages',
392
+
393
+ * its action called 'display', and we pass a param to select the view file
394
+
395
+ * to use (in this case, src/Template/Pages/home.ctp)...
396
+
397
+ */
398
+
399
+ $routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
400
+
401
+
402
+
403
+ /**
404
+
405
+ * ...and connect the rest of 'Pages' controller's URLs.
406
+
407
+ */
408
+
409
+ $routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
410
+
411
+
412
+
413
+ /**
414
+
415
+ * Connect catchall routes for all controllers.
416
+
417
+ *
418
+
419
+ * Using the argument `DashedRoute`, the `fallbacks` method is a shortcut for
420
+
421
+ *
422
+
423
+ * ```
424
+
425
+ * $routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);
426
+
427
+ * $routes->connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);
428
+
429
+ * ```
430
+
431
+ *
432
+
433
+ * Any route class can be used with this method, such as:
434
+
435
+ * - DashedRoute
436
+
437
+ * - InflectedRoute
438
+
439
+ * - Route
440
+
441
+ * - Or your own route class
442
+
443
+ *
444
+
445
+ * You can remove these routes once you've connected the
446
+
447
+ * routes you want in your application.
448
+
449
+ */
450
+
451
+ $routes->fallbacks(DashedRoute::class);
452
+
453
+ });
454
+
455
+
456
+
457
+ /**
458
+
459
+ * If you need a different set of middleware or none at all,
460
+
461
+ * open new scope and define routes there.
462
+
463
+ *
464
+
465
+ * ```
466
+
467
+ * Router::scope('/api', function (RouteBuilder $routes) {
468
+
469
+ * // No $routes->applyMiddleware() here.
470
+
471
+ * // Connect API actions here.
472
+
473
+ * });
474
+
475
+ * ```
476
+
477
+ */
478
+
479
+
480
+
481
+ ```
482
+
483
+
484
+
77
485
  ### 補足
78
486
 
79
487