Thinkphp5.1定義空操作

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章