質問編集履歴
2
エラー詳細等を記載しました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
submitしたところ、以下のエラーメッセージが出力されました。
|
|
10
10
|
```
|
|
11
|
-
CSRF token mismatch
|
|
11
|
+
CSRF token mismatch.
|
|
12
|
+
Cake\Http\Exception\InvalidCsrfTokenException
|
|
12
13
|
```
|
|
13
14
|
|
|
14
15
|
### ソースコード
|
1
遅くなり申し訳ありません。追記しました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -36,6 +36,210 @@
|
|
|
36
36
|
</div>
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
src/Application.php
|
|
40
|
+
```PHP
|
|
41
|
+
<?php
|
|
42
|
+
/**
|
|
43
|
+
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
|
44
|
+
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
|
45
|
+
*
|
|
46
|
+
* Licensed under The MIT License
|
|
47
|
+
* For full copyright and license information, please see the LICENSE.txt
|
|
48
|
+
* Redistributions of files must retain the above copyright notice.
|
|
49
|
+
*
|
|
50
|
+
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
|
51
|
+
* @link https://cakephp.org CakePHP(tm) Project
|
|
52
|
+
* @since 3.3.0
|
|
53
|
+
* @license https://opensource.org/licenses/mit-license.php MIT License
|
|
54
|
+
*/
|
|
55
|
+
namespace App;
|
|
56
|
+
|
|
57
|
+
use Cake\Core\Configure;
|
|
58
|
+
use Cake\Core\Exception\MissingPluginException;
|
|
59
|
+
use Cake\Error\Middleware\ErrorHandlerMiddleware;
|
|
60
|
+
use Cake\Http\BaseApplication;
|
|
61
|
+
use Cake\Http\Middleware\CsrfProtectionMiddleware;
|
|
62
|
+
use Cake\Routing\Middleware\AssetMiddleware;
|
|
63
|
+
use Cake\Routing\Middleware\RoutingMiddleware;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Application setup class.
|
|
67
|
+
*
|
|
68
|
+
* This defines the bootstrapping logic and middleware layers you
|
|
69
|
+
* want to use in your application.
|
|
70
|
+
*/
|
|
71
|
+
class Application extends BaseApplication
|
|
72
|
+
{
|
|
73
|
+
/**
|
|
74
|
+
* {@inheritDoc}
|
|
75
|
+
*/
|
|
76
|
+
public function bootstrap()
|
|
77
|
+
{
|
|
78
|
+
// Call parent to load bootstrap from files.
|
|
79
|
+
parent::bootstrap();
|
|
80
|
+
|
|
81
|
+
if (PHP_SAPI === 'cli') {
|
|
82
|
+
try {
|
|
83
|
+
$this->addPlugin('Bake');
|
|
84
|
+
} catch (MissingPluginException $e) {
|
|
85
|
+
// Do not halt if the plugin is missing
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
$this->addPlugin('Migrations');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* Only try to load DebugKit in development mode
|
|
93
|
+
* Debug Kit should not be installed on a production system
|
|
94
|
+
*/
|
|
95
|
+
if (Configure::read('debug')) {
|
|
96
|
+
$this->addPlugin(\DebugKit\Plugin::class);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Setup the middleware queue your application will use.
|
|
102
|
+
*
|
|
103
|
+
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup.
|
|
104
|
+
* @return \Cake\Http\MiddlewareQueue The updated middleware queue.
|
|
105
|
+
*/
|
|
106
|
+
public function middleware($middlewareQueue)
|
|
107
|
+
{
|
|
108
|
+
$middlewareQueue
|
|
109
|
+
// Catch any exceptions in the lower layers,
|
|
110
|
+
// and make an error page/response
|
|
111
|
+
->add(ErrorHandlerMiddleware::class)
|
|
112
|
+
|
|
113
|
+
// Handle plugin/theme assets like CakePHP normally does.
|
|
114
|
+
->add(new AssetMiddleware([
|
|
115
|
+
'cacheTime' => Configure::read('Asset.cacheTime')
|
|
116
|
+
]))
|
|
117
|
+
|
|
118
|
+
// Add routing middleware.
|
|
119
|
+
// Routes collection cache enabled by default, to disable route caching
|
|
120
|
+
// pass null as cacheConfig, example: `new RoutingMiddleware($this)`
|
|
121
|
+
// you might want to disable this cache in case your routing is extremely simple
|
|
122
|
+
->add(new RoutingMiddleware($this, '_cake_routes_'))
|
|
123
|
+
|
|
124
|
+
// Add csrf middleware.
|
|
125
|
+
->add(new CsrfProtectionMiddleware([
|
|
126
|
+
'httpOnly' => true
|
|
127
|
+
]));
|
|
128
|
+
return $middlewareQueue;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
config/routes.php
|
|
135
|
+
```PHP
|
|
136
|
+
<?php
|
|
137
|
+
/**
|
|
138
|
+
* Routes configuration
|
|
139
|
+
*
|
|
140
|
+
* In this file, you set up routes to your controllers and their actions.
|
|
141
|
+
* Routes are very important mechanism that allows you to freely connect
|
|
142
|
+
* different URLs to chosen controllers and their actions (functions).
|
|
143
|
+
*
|
|
144
|
+
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
|
145
|
+
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
|
146
|
+
*
|
|
147
|
+
* Licensed under The MIT License
|
|
148
|
+
* For full copyright and license information, please see the LICENSE.txt
|
|
149
|
+
* Redistributions of files must retain the above copyright notice.
|
|
150
|
+
*
|
|
151
|
+
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
|
152
|
+
* @link https://cakephp.org CakePHP(tm) Project
|
|
153
|
+
* @license https://opensource.org/licenses/mit-license.php MIT License
|
|
154
|
+
*/
|
|
155
|
+
use Cake\Http\Middleware\CsrfProtectionMiddleware;
|
|
156
|
+
use Cake\Routing\RouteBuilder;
|
|
157
|
+
use Cake\Routing\Router;
|
|
158
|
+
use Cake\Routing\Route\DashedRoute;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The default class to use for all routes
|
|
162
|
+
*
|
|
163
|
+
* The following route classes are supplied with CakePHP and are appropriate
|
|
164
|
+
* to set as the default:
|
|
165
|
+
*
|
|
166
|
+
* - Route
|
|
167
|
+
* - InflectedRoute
|
|
168
|
+
* - DashedRoute
|
|
169
|
+
*
|
|
170
|
+
* If no call is made to `Router::defaultRouteClass()`, the class used is
|
|
171
|
+
* `Route` (`Cake\Routing\Route\Route`)
|
|
172
|
+
*
|
|
173
|
+
* Note that `Route` does not do any inflections on URLs which will result in
|
|
174
|
+
* inconsistently cased URLs when used with `:plugin`, `:controller` and
|
|
175
|
+
* `:action` markers.
|
|
176
|
+
*
|
|
177
|
+
* Cache: Routes are cached to improve performance, check the RoutingMiddleware
|
|
178
|
+
* constructor in your `src/Application.php` file to change this behavior.
|
|
179
|
+
*
|
|
180
|
+
*/
|
|
181
|
+
Router::defaultRouteClass(DashedRoute::class);
|
|
182
|
+
|
|
183
|
+
Router::scope('/', function (RouteBuilder $routes) {
|
|
184
|
+
// Register scoped middleware for in scopes.
|
|
185
|
+
$routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([
|
|
186
|
+
'httpOnly' => true
|
|
187
|
+
]));
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Apply a middleware to the current route scope.
|
|
191
|
+
* Requires middleware to be registered via `Application::routes()` with `registerMiddleware()`
|
|
192
|
+
*/
|
|
193
|
+
$routes->applyMiddleware('csrf');
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Here, we are connecting '/' (base path) to a controller called 'Pages',
|
|
197
|
+
* its action called 'display', and we pass a param to select the view file
|
|
198
|
+
* to use (in this case, src/Template/Pages/home.ctp)...
|
|
199
|
+
*/
|
|
200
|
+
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* ...and connect the rest of 'Pages' controller's URLs.
|
|
204
|
+
*/
|
|
205
|
+
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Connect catchall routes for all controllers.
|
|
209
|
+
*
|
|
210
|
+
* Using the argument `DashedRoute`, the `fallbacks` method is a shortcut for
|
|
211
|
+
*
|
|
212
|
+
* ```
|
|
213
|
+
* $routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);
|
|
214
|
+
* $routes->connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* Any route class can be used with this method, such as:
|
|
218
|
+
* - DashedRoute
|
|
219
|
+
* - InflectedRoute
|
|
220
|
+
* - Route
|
|
221
|
+
* - Or your own route class
|
|
222
|
+
*
|
|
223
|
+
* You can remove these routes once you've connected the
|
|
224
|
+
* routes you want in your application.
|
|
225
|
+
*/
|
|
226
|
+
$routes->fallbacks(DashedRoute::class);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* If you need a different set of middleware or none at all,
|
|
231
|
+
* open new scope and define routes there.
|
|
232
|
+
*
|
|
233
|
+
* ```
|
|
234
|
+
* Router::scope('/api', function (RouteBuilder $routes) {
|
|
235
|
+
* // No $routes->applyMiddleware() here.
|
|
236
|
+
* // Connect API actions here.
|
|
237
|
+
* });
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
|
|
39
243
|
### 補足
|
|
40
244
|
|
|
41
245
|
画面のソースにはhiddenのtokenが出力され、
|