異常?類似以下這種
那么在調試好的運行中的網站 大家一定不會想要見到這種錯誤吧 (用戶體驗在哪里)
接下來就告訴大家如何 通過配置自定義類來 跳轉404錯誤頁面
1.關閉所有app_debug 即 'app_debug' => true,
2.在config.php中配置自定義類
'exception_handle' => '\\app\\common\\exception\\Http',
3.創建類 入下圖創建文件夾及文件
4.在Http.php中寫入
<?php
namespace app\common\exception;
use Exception;
use think\exception\Handle;
class Http extends Handle
{
public function render(\Exception $e){
if(config('app_debug')){
//如果開啟debug則正常報錯
return parent::render($e);
}else{
//404頁面 自行定義
header("Location:".url('home/index/index'));
}
}
}
現在 可以通過關閉/開啟debug來實現404/報錯了