空模塊
'exception_handle' => function(Exception $e){ // 參數驗證錯誤 if ($e instanceof \think\exception\ValidateException) { return json($e->getError(), 422); } // 請求異常 if ($e instanceof \think\exception\HttpException && request()->isAjax()) { return response($e->getMessage(), $e->getStatusCode()); } return redirect(url('home/index/index'));//重定向至自定義錯誤提示頁面 },
或者
'exception_handle' => '\\app\\common\\exception\\Http',
<?php namespace app\common\exception; use Exception; use think\exception\Handle; use think\exception\HttpException; class Http extends Handle { public function render(Exception $e) { // 參數驗證錯誤 if ($e instanceof ValidateException) { return json($e->getError(), 422); } // 請求異常 if ($e instanceof HttpException && request()->isAjax()) { return response($e->getMessage(), $e->getStatusCode()); } //TODO::開發者對異常的操作 //可以在此交由系統處理 return redirect(url('home/index/index'));//重定向至自定義錯誤提示頁面 //return parent::render($e); } } ?>
空控制器
// 默認的空控制器名 'empty_controller' => 'Error',
<?php namespace app\home\controller; use think\Controller; use think\Request; class Error extends Controller { public function index(Request $request) { $this->redirect(url('home/index/index'));//空控制器處理 } }
空方法
public function _empty(){ $this->redirect(url('home/index/index'));//空方法處理 }