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, the view display page and the related operation skills of the controller call in the form of examples. Friends in need. 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 needs to 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:
您查找的页面不存在,还有 6 秒,页面将自动跳转首页...
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, '~~~非法请求~~~'); }
404 The effect is as follows:
The above is the entire content of this article. I hope it will be helpful to everyone’s study. More For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
About ThinkPHP’s method of using UTFWry address library for IP positioning
The above is the detailed content of About the method of setting http status pages such as 404 and 403 in thinkPHP5 framework. For more information, please follow other related articles on the PHP Chinese website!