質問編集履歴
7
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
- cakephp3.6
|
6
6
|
|
7
|
+
- nginx
|
8
|
+
|
7
9
|
|
8
10
|
|
9
11
|
|
@@ -12,6 +14,8 @@
|
|
12
14
|
|
13
15
|
`throw new NotFoundException();`しても、サーバ(nginx)のエラーページが表示される
|
14
16
|
|
17
|
+
また、存在しないURLにアクセスしてもnginxのエラーページが表示される
|
18
|
+
|
15
19
|
|
16
20
|
|
17
21
|
|
6
エラー追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -327,3 +327,39 @@
|
|
327
327
|
|
328
328
|
|
329
329
|
英語のページも漁ってみたのですが、twigを使った方法がなく……困っております。
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
# 追記
|
338
|
+
|
339
|
+
nginxのエラーです。
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
`/a`など、存在しないアドレスにアクセスした時です。
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
```
|
348
|
+
|
349
|
+
[Cake\Routing\Exception\MissingControllerException] Controller class A could not be found.
|
350
|
+
|
351
|
+
Exception Attributes: array (
|
352
|
+
|
353
|
+
'class' => 'A',
|
354
|
+
|
355
|
+
'plugin' => false,
|
356
|
+
|
357
|
+
'prefix' => false,
|
358
|
+
|
359
|
+
'_ext' => false,
|
360
|
+
|
361
|
+
)
|
362
|
+
|
363
|
+
Request URL: /a
|
364
|
+
|
365
|
+
```
|
5
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -292,7 +292,23 @@
|
|
292
292
|
|
293
293
|
|
294
294
|
|
295
|
-
---
|
295
|
+
---
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
上記コードを書いておりますが、
|
300
|
+
|
301
|
+
「`beforeRender`」メソッドまで処理が来ているのにもかかわらず、
|
302
|
+
|
303
|
+
画面がレンダリングされず、nginxのエラーページが表示されてしまします。
|
304
|
+
|
305
|
+
この原因がわからず、困っております。
|
306
|
+
|
307
|
+
おわかりの方、「多分これかな?」という心当たりのある方、
|
308
|
+
|
309
|
+
情報をいただけないでしょうか。
|
310
|
+
|
311
|
+
よろしくお願いいたします。
|
296
312
|
|
297
313
|
|
298
314
|
|
4
質問自体を変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Cake
|
1
|
+
CakePHP3.6 NotFoundExceptionで画面がレンダリングされない
|
test
CHANGED
@@ -8,157 +8,291 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
+
# 困っていること
|
12
|
+
|
13
|
+
`throw new NotFoundException();`しても、サーバ(nginx)のエラーページが表示される
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
11
|
-
# や
|
19
|
+
# やっていること
|
12
|
-
|
20
|
+
|
21
|
+
|
22
|
+
|
13
|
-
|
23
|
+
以下の設定を行っております。
|
14
|
-
|
15
|
-
|
24
|
+
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
Cakephpでのtwigの呼び出しは以下を利用
|
20
|
-
|
21
|
-
[http
|
25
|
+
[※参考にしたサイト様](http://moblog.absgexp.net/cakeerr/#i)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
|
28
|
-
|
29
|
-
|
27
|
+
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
|
34
|
-
|
35
|
-
|
29
|
+
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
|
39
|
-
**
|
31
|
+
**config/app.php**
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
'Error' => [
|
38
|
+
|
39
|
+
'errorLevel' => E_ALL,
|
40
|
+
|
41
|
+
'exceptionRenderer' => 'Cake\Error\ExceptionRenderer',
|
42
|
+
|
43
|
+
'skipLog' => [],
|
44
|
+
|
45
|
+
'log' => true,
|
46
|
+
|
47
|
+
'trace' => true,
|
48
|
+
|
49
|
+
],
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
---
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
**Controller/ErrorController.php**
|
40
60
|
|
41
61
|
|
42
62
|
|
43
63
|
```php
|
44
64
|
|
65
|
+
<?php
|
66
|
+
|
67
|
+
/**
|
68
|
+
|
69
|
+
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
70
|
+
|
71
|
+
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
72
|
+
|
73
|
+
*
|
74
|
+
|
75
|
+
* Licensed under The MIT License
|
76
|
+
|
77
|
+
* For full copyright and license information, please see the LICENSE.txt
|
78
|
+
|
79
|
+
* Redistributions of files must retain the above copyright notice.
|
80
|
+
|
81
|
+
*
|
82
|
+
|
83
|
+
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
84
|
+
|
85
|
+
* @link https://cakephp.org CakePHP(tm) Project
|
86
|
+
|
87
|
+
* @since 3.3.4
|
88
|
+
|
89
|
+
* @license https://opensource.org/licenses/mit-license.php MIT License
|
90
|
+
|
91
|
+
*/
|
92
|
+
|
93
|
+
namespace App\Controller;
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
use Cake\Controller\Component\AuthComponent;
|
98
|
+
|
99
|
+
use Cake\Event\Event;
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
/**
|
104
|
+
|
105
|
+
* Error Handling Controller
|
106
|
+
|
107
|
+
*
|
108
|
+
|
109
|
+
* Controller used by ExceptionRenderer to render error responses.
|
110
|
+
|
111
|
+
*/
|
112
|
+
|
113
|
+
class ErrorController extends AppController
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
/**
|
118
|
+
|
119
|
+
* Initialization hook method.
|
120
|
+
|
121
|
+
*
|
122
|
+
|
123
|
+
* @return void
|
124
|
+
|
125
|
+
* @throws \Exception
|
126
|
+
|
127
|
+
*/
|
128
|
+
|
129
|
+
public function initialize()
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
$this->loadComponent('RequestHandler');
|
134
|
+
|
135
|
+
$this->loadComponent('Auth');
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
$this->Auth->allow();
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
/**
|
146
|
+
|
147
|
+
* beforeFilter callback.
|
148
|
+
|
149
|
+
*
|
150
|
+
|
151
|
+
* @param \Cake\Event\Event $event Event.
|
152
|
+
|
153
|
+
* @return \Cake\Http\Response|null|void
|
154
|
+
|
155
|
+
*/
|
156
|
+
|
157
|
+
public function beforeFilter(Event $event)
|
158
|
+
|
159
|
+
{
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
/**
|
166
|
+
|
167
|
+
* beforeRender callback.
|
168
|
+
|
169
|
+
*
|
170
|
+
|
171
|
+
* @param \Cake\Event\Event $event Event.
|
172
|
+
|
173
|
+
* @return \Cake\Http\Response|null|void
|
174
|
+
|
175
|
+
*/
|
176
|
+
|
177
|
+
public function beforeRender(Event $event)
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
parent::beforeRender($event);
|
182
|
+
|
183
|
+
$this->viewBuilder()->setTemplatePath('Error');
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
/**
|
190
|
+
|
191
|
+
* afterFilter callback.
|
192
|
+
|
193
|
+
*
|
194
|
+
|
195
|
+
* @param \Cake\Event\Event $event Event.
|
196
|
+
|
197
|
+
* @return \Cake\Http\Response|null|void
|
198
|
+
|
199
|
+
*/
|
200
|
+
|
201
|
+
public function afterFilter(Event $event)
|
202
|
+
|
203
|
+
{
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
```
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
---
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
**Template/Layout/default.ctp**
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
```
|
226
|
+
|
227
|
+
<!DOCTYPE html>
|
228
|
+
|
229
|
+
<html>
|
230
|
+
|
231
|
+
<head>
|
232
|
+
|
233
|
+
<title>
|
234
|
+
|
235
|
+
エラーページ
|
236
|
+
|
237
|
+
</title>
|
238
|
+
|
239
|
+
</head>
|
240
|
+
|
241
|
+
<body>
|
242
|
+
|
243
|
+
<div id="container">
|
244
|
+
|
245
|
+
<div id="header">
|
246
|
+
|
247
|
+
<h1>エラー</h1>
|
248
|
+
|
249
|
+
</div>
|
250
|
+
|
251
|
+
<div id="content">
|
252
|
+
|
45
|
-
{{ _view.
|
253
|
+
{{ _view.fetch('content')|raw }}
|
254
|
+
|
255
|
+
</div>
|
256
|
+
|
257
|
+
<div id="footer">
|
258
|
+
|
259
|
+
</div>
|
260
|
+
|
261
|
+
</div>
|
262
|
+
|
263
|
+
</body>
|
264
|
+
|
265
|
+
</html>
|
266
|
+
|
267
|
+
```
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
---
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
**Template/Error/error400.twig**
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
```
|
284
|
+
|
285
|
+
{{ _view.start('main') }}
|
46
286
|
|
47
287
|
not found
|
48
288
|
|
289
|
+
{{ _view.end }}
|
290
|
+
|
49
|
-
```
|
291
|
+
```
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
292
|
+
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
293
|
+
|
58
|
-
|
59
|
-
|
294
|
+
|
60
|
-
|
61
|
-
server error
|
62
|
-
|
63
|
-
```
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
**Template/Layout/error.twig**
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
```php
|
72
|
-
|
73
|
-
<!DOCTYPE html>
|
74
|
-
|
75
|
-
<html>
|
76
|
-
|
77
|
-
<head>
|
78
|
-
|
79
|
-
{{ Html.charset() | raw }}
|
80
|
-
|
81
|
-
<title>
|
82
|
-
|
83
|
-
エラーページ
|
84
|
-
|
85
|
-
</title>
|
86
|
-
|
87
|
-
</head>
|
88
|
-
|
89
|
-
<body>
|
90
|
-
|
91
|
-
<div id="container">
|
92
|
-
|
93
|
-
<div id="header">
|
94
|
-
|
95
|
-
<h1>{{ __('Error') }}</h1>
|
96
|
-
|
97
|
-
</div>
|
98
|
-
|
99
|
-
<div id="content">
|
100
|
-
|
101
|
-
{{ flash.render() }}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
{{ _view.fetch('content') }}
|
106
|
-
|
107
|
-
</div>
|
108
|
-
|
109
|
-
<div id="footer">
|
110
|
-
|
111
|
-
</div>
|
112
|
-
|
113
|
-
</div>
|
114
|
-
|
115
|
-
</body>
|
116
|
-
|
117
|
-
</html>
|
118
|
-
|
119
|
-
```
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
その後、エラー処理部分で、
|
124
|
-
|
125
|
-
`throw new NotFoundException();`を書きました。
|
126
|
-
|
127
|
-
もちろん`use Cake\Http\Exception\NotFoundException;`を先頭に書いております。
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
しかし、サーバのエラーページ(今回nginxを使っているので、nginxのデフォルトエラーページ)が表示されます。
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
エラーページはtwigが使えないのかと思い、
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
- `error400.ctp`
|
140
|
-
|
141
|
-
- `error500.ctp`
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
も残してありますが、nginxのデフォルトエラーページに変わりはありませんでした。
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
295
|
+
---。
|
152
|
-
|
153
|
-
0. cakephp3のtwigでカスタムエラーページの作成方法はこれであっているのでしょうか?
|
154
|
-
|
155
|
-
0. nginxで足りていない設定があるのでしょうか?
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
以上、ご存知の方がいらっしゃいましたら、ご教示いただけますと幸いです。
|
162
296
|
|
163
297
|
|
164
298
|
|
@@ -177,39 +311,3 @@
|
|
177
311
|
|
178
312
|
|
179
313
|
英語のページも漁ってみたのですが、twigを使った方法がなく……困っております。
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
# 追記
|
188
|
-
|
189
|
-
以下ページを参考にカスタムエラーページを作成してみたのですが、
|
190
|
-
|
191
|
-
`AppErrorController.php`で、
|
192
|
-
|
193
|
-
`$this->viewBuilder()->setTemplatePath('Error');`だとページがレンダリングされず、
|
194
|
-
|
195
|
-
`$this->viewBuilder()->templatePath('Error');`だと、ページが正常に表示されます。
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
ただ、`$this->viewBuilder()->templatePath('Error');`は`deprecated`になっています……
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
http://moblog.absgexp.net/cakeerr/#i-5
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
# 追記2
|
212
|
-
|
213
|
-
`deprecationWarning`を`$this->viewBuilder()->setTemplatePath('Error');`の上などに入れて、ワーニングメッセージを表示させると、こちらが指定したページが読み込まれる事がわかりました。
|
214
|
-
|
215
|
-
しかし、これがないとエラーページが表示されません。。。
|
3
追記2
test
CHANGED
File without changes
|
test
CHANGED
@@ -203,3 +203,13 @@
|
|
203
203
|
|
204
204
|
|
205
205
|
http://moblog.absgexp.net/cakeerr/#i-5
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
# 追記2
|
212
|
+
|
213
|
+
`deprecationWarning`を`$this->viewBuilder()->setTemplatePath('Error');`の上などに入れて、ワーニングメッセージを表示させると、こちらが指定したページが読み込まれる事がわかりました。
|
214
|
+
|
215
|
+
しかし、これがないとエラーページが表示されません。。。
|
2
謎追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -177,3 +177,29 @@
|
|
177
177
|
|
178
178
|
|
179
179
|
英語のページも漁ってみたのですが、twigを使った方法がなく……困っております。
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
# 追記
|
188
|
+
|
189
|
+
以下ページを参考にカスタムエラーページを作成してみたのですが、
|
190
|
+
|
191
|
+
`AppErrorController.php`で、
|
192
|
+
|
193
|
+
`$this->viewBuilder()->setTemplatePath('Error');`だとページがレンダリングされず、
|
194
|
+
|
195
|
+
`$this->viewBuilder()->templatePath('Error');`だと、ページが正常に表示されます。
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
ただ、`$this->viewBuilder()->templatePath('Error');`は`deprecated`になっています……
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
http://moblog.absgexp.net/cakeerr/#i-5
|
1
error.twig追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,6 +64,62 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
|
67
|
+
**Template/Layout/error.twig**
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
```php
|
72
|
+
|
73
|
+
<!DOCTYPE html>
|
74
|
+
|
75
|
+
<html>
|
76
|
+
|
77
|
+
<head>
|
78
|
+
|
79
|
+
{{ Html.charset() | raw }}
|
80
|
+
|
81
|
+
<title>
|
82
|
+
|
83
|
+
エラーページ
|
84
|
+
|
85
|
+
</title>
|
86
|
+
|
87
|
+
</head>
|
88
|
+
|
89
|
+
<body>
|
90
|
+
|
91
|
+
<div id="container">
|
92
|
+
|
93
|
+
<div id="header">
|
94
|
+
|
95
|
+
<h1>{{ __('Error') }}</h1>
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<div id="content">
|
100
|
+
|
101
|
+
{{ flash.render() }}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
{{ _view.fetch('content') }}
|
106
|
+
|
107
|
+
</div>
|
108
|
+
|
109
|
+
<div id="footer">
|
110
|
+
|
111
|
+
</div>
|
112
|
+
|
113
|
+
</div>
|
114
|
+
|
115
|
+
</body>
|
116
|
+
|
117
|
+
</html>
|
118
|
+
|
119
|
+
```
|
120
|
+
|
121
|
+
|
122
|
+
|
67
123
|
その後、エラー処理部分で、
|
68
124
|
|
69
125
|
`throw new NotFoundException();`を書きました。
|