1.創建一個錯誤文件Error.php
D:\phpstudy_pro\WWW\myvue\api\application\index\controller\Error.php
2.當訪問一個不存在的控制器是觸發空操作
<?php
namespace app\index\controller;
use think\Controller;
use think\facade\Request;
class Error extends Controller
{
public function index()
{
return [404, 'no found '. Request::controller().' controller'];
}
public function _empty($func)
{
return [400, 'no such service as '.$func];
}
}
控制器使用 繼承空操作
<?php
namespace app\index\controller;
class Index extends Error
{
}
顯示結果頁面
參考:thinkphp空操作
https://www.kancloud.cn/manual/thinkphp5_1/353982