选项 |
数据类型 |
描述 |
错误级别 |
int |
Option |
Data Type |
Description |
errorLevel |
int |
The level of errors you are interested in capturing. Use the built-in php error constants, and bitmasks to select the level of error you are interested in. |
trace |
bool |
Include stack traces for errors in log files. Stack traces will be included in the log after each error. This is helpful for finding where/when errors are being raised. |
exceptionRenderer |
string |
The class responsible for rendering uncaught exceptions. If you choose a custom class, you should place the file for that class in src/Error. This class needs to implement a render() method. |
log |
bool |
When true, exceptions + their stack traces will be logged to CakeLogLog. |
skipLog |
array |
An array of exception class names that should not be logged. This is useful to remove NotFoundExceptions or other common, but uninteresting logs messages. |
extraFatalErrorMemory |
int |
Set to the number of megabytes to increase the memory limit by, when a fatal error is encountered. This allows breathing room to complete logging or error handling. |
您有兴趣捕获的错误级别。使用内置的 php 错误常量和位掩码来选择您感兴趣的错误级别。 |
跟踪 |
布尔 |
在日志文件中包含错误的堆栈跟踪。每次错误后,堆栈跟踪将包含在日志中。这有助于查找发生错误的位置/时间。 |
异常渲染器 |
字符串 |
负责渲染未捕获异常的类。如果您选择自定义类,则应将该类的文件放置在 src/Error中。该类需要实现 render() 方法。
|
日志 |
布尔 |
<?php use Cake\Http\Middleware\CsrfProtectionMiddleware;
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
$routes->setRouteClass(DashedRoute::class);
$routes->scope('/', function (RouteBuilder $builder) {
$builder->registerMiddleware('csrf', new CsrfProtectionMiddleware([
'httpOnly' => true,
]));
$builder->applyMiddleware('csrf');
//$builder->connect('/pages',['controller'=>'Pages','action'=>'display', 'home']);
$builder->connect('/exception/:arg1/:arg2',
['controller'=>'Exps','action'=>'index'],
['pass' => ['arg1', 'arg2']]);
$builder->fallbacks();
});
当为 true 时,异常及其堆栈跟踪将被记录到 CakeLogLog。
|
跳过日志 |
数组 |
不应记录的异常类名称数组。这对于删除 NotFoundExceptions 或其他常见但无趣的日志消息很有用。
|
额外的致命错误内存 |
int |
设置为在遇到致命错误时增加内存限制的兆字节数。这为完成日志记录或错误处理提供了喘息的空间。 |
表>
<?php namespace App\Controller;
use App\Controller\AppController;
use Cake\Core\Exception\Exception;
class ExpsController extends AppController {
public function index($arg1,$arg2) {
try{
$this->set('argument1',$arg1);
$this->set('argument2',$arg2);
if(($arg1 > 1 || $arg1 > 10) || ($arg2 10))
throw new Exception("One of the number is out of range [1-10].");
} catch(\Exception $ex){
echo $ex->getMessage();
}
}
}
?>
示例
在 config/routes.php 文件中进行更改,如以下代码所示。
config/routes.php
在
src/Controller/ExpsController.php 创建
This is CakePHP tutorial and this is an example of Passed arguments.<br>
Argument-1: =$argument1?><br>
Argument-2: =$argument2?><br>
ExpsController.php 文件。
将以下代码复制到控制器文件中。
src/Controller/ExpsController.php
在src/Template处创建一个目录Exps,并在该目录下创建一个名为index.php的View文件。将以下代码复制到该文件中。
src/Template/Exps/index.php
通过访问以下 URL 来执行上述示例。
http://localhost/cakephp4/Exception/5/0
输出
执行后,您将收到以下输出。