
環境
- php 7.2
- cakephp3.6
- nginx
困っていること
throw new NotFoundException();
しても、サーバ(nginx)のエラーページが表示される
また、存在しないURLにアクセスしてもnginxのエラーページが表示される
やっていること
以下の設定を行っております。
※参考にしたサイト様
config/app.php
'Error' => [ 'errorLevel' => E_ALL, 'exceptionRenderer' => 'Cake\Error\ExceptionRenderer', 'skipLog' => [], 'log' => true, 'trace' => true, ],
Controller/ErrorController.php
php
1<?php 2/** 3 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) 4 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) 5 * 6 * Licensed under The MIT License 7 * For full copyright and license information, please see the LICENSE.txt 8 * Redistributions of files must retain the above copyright notice. 9 * 10 * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) 11 * @link https://cakephp.org CakePHP(tm) Project 12 * @since 3.3.4 13 * @license https://opensource.org/licenses/mit-license.php MIT License 14 */ 15namespace App\Controller; 16 17use Cake\Controller\Component\AuthComponent; 18use Cake\Event\Event; 19 20/** 21 * Error Handling Controller 22 * 23 * Controller used by ExceptionRenderer to render error responses. 24 */ 25class ErrorController extends AppController 26{ 27 /** 28 * Initialization hook method. 29 * 30 * @return void 31 * @throws \Exception 32 */ 33 public function initialize() 34 { 35 $this->loadComponent('RequestHandler'); 36 $this->loadComponent('Auth'); 37 38 $this->Auth->allow(); 39 } 40 41 /** 42 * beforeFilter callback. 43 * 44 * @param \Cake\Event\Event $event Event. 45 * @return \Cake\Http\Response|null|void 46 */ 47 public function beforeFilter(Event $event) 48 { 49 } 50 51 /** 52 * beforeRender callback. 53 * 54 * @param \Cake\Event\Event $event Event. 55 * @return \Cake\Http\Response|null|void 56 */ 57 public function beforeRender(Event $event) 58 { 59 parent::beforeRender($event); 60 $this->viewBuilder()->setTemplatePath('Error'); 61 } 62 63 /** 64 * afterFilter callback. 65 * 66 * @param \Cake\Event\Event $event Event. 67 * @return \Cake\Http\Response|null|void 68 */ 69 public function afterFilter(Event $event) 70 { 71 } 72} 73
Template/Layout/default.ctp
<!DOCTYPE html> <html> <head> <title> エラーページ </title> </head> <body> <div id="container"> <div id="header"> <h1>エラー</h1> </div> <div id="content"> {{ _view.fetch('content')|raw }} </div> <div id="footer"> </div> </div> </body> </html>
Template/Error/error400.twig
{{ _view.start('main') }} not found {{ _view.end }}
上記コードを書いておりますが、
「beforeRender
」メソッドまで処理が来ているのにもかかわらず、
画面がレンダリングされず、nginxのエラーページが表示されてしまします。
この原因がわからず、困っております。
おわかりの方、「多分これかな?」という心当たりのある方、
情報をいただけないでしょうか。
よろしくお願いいたします。
参考
英語のページも漁ってみたのですが、twigを使った方法がなく……困っております。
追記
nginxのエラーです。
/a
など、存在しないアドレスにアクセスした時です。
[Cake\Routing\Exception\MissingControllerException] Controller class A could not be found. Exception Attributes: array ( 'class' => 'A', 'plugin' => false, 'prefix' => false, '_ext' => false, ) Request URL: /a



