在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全/ slim框架如何自定義 請求方式錯誤

slim框架如何自定義 請求方式錯誤

比如規(guī)定了POST方式請求接口,但是GET來請求會報如下圖錯誤
圖片描述

那么如何自定義返回的錯誤呢?比如返回:
{"error":"Method not allowed"}

回答
編輯回答
墨沫
// 重寫默認的notAllowedHandler
$container['notAllowedHandler'] = function ()
{
    return function ($req, $res, $allowMethod) {
        return $res->withJson([
            "status" => 0,
            "info" => "請求方法錯誤",
            "data" => $allowMethod
        ]);
    };
};
2018年4月22日 00:50