我想捕捉所有404错误(控制器找不到)在我的新蛋糕应用程序。但我不知道怎么做。
有什么配置吗?或者我必须自己抓到抛出的错误?如果是,在哪里?
发布于 2015-04-20 18:25:57
这里有一种方法,这是可行的。定义自己的错误处理程序,它扩展了默认的ErrorHandler
<?php
// Custom Handler - goes in src/Error/AppError.php
namespace App\Error;
use Cake\Routing\Exception\MissingControllerException;
use Cake\Error\ErrorHandler;
class AppError extends ErrorHandler
{
public function _displayException($exception)
{
if ($exception instanceof MissingControllerException) {
// Here handle MissingControllerException by yourself
} else {
parent::_displayException($exception);
}
}
}然后将此处理程序注册为默认处理程序。
// Register handler in config/bootstrap.php
use App\Error\AppError;
$errorHandler = new AppError();
$errorHandler->register();http://book.cakephp.org/3.0/en/development/errors.html
https://stackoverflow.com/questions/29753450
复制相似问题