Thinkphp5 設定403 404等http狀態頁面
阿新 • • 發佈:2019-02-05
要做到這一點,首先要在你的配置檔案將除錯模式關閉(在開發階段要開啟):
'app_debug'
=> false,
然後在配置檔案中配置404等頁面的模板路徑(APP_PATH指的是application路徑):
'http_exception_template'
=> [ 404 => APP_PATH.
'404.html'
, 403 => APP_PATH.
'404.html'
,]
404頁面部分程式碼如下:
<span>404錯誤</sapan>
測試 controller
if
(Request::instance()->isAjax()) {
$data
= input();
$info
= [];
$where
=
''
;
switch
(
$data
[
'msg'
]) {
case
'驗證碼'
:
$info
= [
'y'
=>
'輸入正確'
,
'n'
=>
'輸入錯誤'
,
];
$where
= session::get(
'admin_login_session'
) == md5(
$data
[
'param'
]);
break
;
}
if
(
$where
) {
echo
'{"info":"'
.
$data
[
'msg'
] .
$info
[
'y'
] .
'","status":"y"}'
;
//注意ValidForm返回格式(json)
}
else
{
echo
'{"info":"'
.
$data
[
'msg'
] .
$info
[
'n'
] .
'","status":"n"}'
;
//注意ValidForm返回格式(json)
}
}
else
{
throw
new
\think\exception\HttpException(403,
'~~~非法請求~~~'
);
}