チュートリアルをしていますが、http://book.cakephp.org/3.0/en/development/errors.html#exception-rendererに従ってください。動作しておらず、空白のページが表示されています。 SRC /エラー/ AppError.phpCakePHP3 - カスタムページエラー404が動作しない
でのconfig/bootstrap.phpのuse App\Error\AppError;
$errorHandler = new AppError();
$errorHandler->register();
で
<?php
namespace App\Error;
use Cake\Error\BaseErrorHandler;
class AppError extends BaseErrorHandler
{
public function _displayError($error, $debug)
{
return 'There has been an error!';
}
public function _displayException($exception)
{
return 'There has been an exception!';
}
public function handleFatalError($code, $description, $file, $line)
{
return 'A fatal error has happened';
}
}
私はSRC /テンプレート/レイアウト/ my_error.ctpでmy_error.ctpを作成します。私のsrc/Template/Error/error404.ctpでは、レイアウトをmy_error.ctpに変更しました。
$this->layout = 'my_error';
最後に、私のコントローラで
use Cake\Network\Exception\NotFoundException;
$staff = $this->Staff->find()->where(['Staff.StaffId = '=> $id, 'Staff.PartnerId = ' =>$this->partnerId])->first();
if (empty($staff)) {
throw new NotFoundException(__('Staff not found'));
}