This article mainly introduces the method of setting 404, 403 and other http status pages in the thinkPHP5 framework. It analyzes the related configuration of the thinkPHP5 framework setting the 404 page, view display page and controller call related operation skills in the form of examples. Friends who need it You can refer to the following example
This article describes the method of setting 404, 403 and other http status pages in the thinkPHP5 framework. Share it with everyone for your reference, the details are as follows:
To do this, you must first turn off the debugging mode in your configuration file (it must be turned on during the development stage):
'app_debug' => false,
Then configure the template path for 404 and other pages in the configuration file config.php (APP_PATH refers to the application path):
'http_exception_template' => [ // 定义404错误的重定向页面地址 404 => APP_PATH.'404.html', // 还可以定义其它的HTTP status 401 => APP_PATH.'401.html', 403 => APP_PATH.'404.html', ],
The 404 page is located in the application directory. The 404.html part of the code is as follows:
<img src="__INDEX__/img/404.png" width="818" height="595" style="display: block;margin: 0 auto;"> <p class="" style="font-size: 36px;margin: 0 auto;text-align: center;color: #323232;"> 您查找的页面不存在,还有 <span id="dd" style="color:darkorange;font-weight: bold;">6</span> 秒,页面将自动跳转首页... </p> <!--倒计时--> <script type="text/javascript"> function run(){ var s = document.getElementById("dd"); if(s.innerHTML == 0){ window.location.href='/'; return false; } s.innerHTML = s.innerHTML * 1 - 1; } window.setInterval("run();", 1000); </script>
Test 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, '~~~非法请求~~~'); }
thinkPHP pops up to confirm before deletion Simple implementation method of the box
The above is the detailed content of How to set 404, 403 and other http status pages in thinkPHP5 framework. For more information, please follow other related articles on the PHP Chinese website!