選項 |
資料型別 |
描述 |
錯誤等級 |
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
輸出
執行後,您將收到以下輸出。