ThinkPHP中自定义错误、成功、异常提示页面的方法

ThinkPHP中自定义错误、成功、异常提示页面的方法

ThinkPHP提供了自带的错误提示页面,但是并不美观,提示信息显示如下:

1.jpg

我们如果想要更换提示页面应该怎么做呢?

以ThinkPHP3.2为例:

立即学习“PHP免费学习笔记(深入)”;

在应用配置文件(应用文件目录/Common/Conf/config.php)中添加:

/* 错误页面模板 */'TMPL_ACTION_ERROR'     =>  'Public/dispatch_jump.html', // 默认错误跳转对应的模板文件''TMPL_ACTION_SUCCESS'   =>  'Public/dispatch_jump.html', // 默认成功跳转对应的模板文件'//'TMPL_EXCEPTION_FILE'   =>  'Public/exception.html',// 异常页面的模板文件

 然后我是在项目公共文件(项目目录/Public)中新建了dispatch_jump.html,模板内容如下:

                    跳转提示                            *{box-sizing:border-box;margin:0;padding:0;font-family:Lantinghei SC,Open Sans,Arial,Hiragino Sans GB,Microsoft YaHei,"微软雅黑",STHeiti,WenQuanYi Micro Hei,SimSun,sans-serif;-webkit-font-smoothing:antialiased}            body{padding:70px 0;background:#edf1f4;font-weight:400;font-size:1pc;-webkit-text-size-adjust:none;color:#333}            a{outline:0;color:#3498db;text-decoration:none;cursor:pointer}            .system-message{margin:20px 5%;padding:40px 20px;background:#fff;box-shadow:1px 1px 1px hsla(0,0%,39%,.1);text-align:center}            .system-message h1{margin:0;margin-bottom:9pt;color:#444;font-weight:400;font-size:40px}            .system-message .jump,.system-message .image{margin:20px 0;padding:0;padding:10px 0;font-weight:400}            .system-message .jump{font-size:14px}            .system-message .jump a{color:#333}            .system-message p{font-size:9pt;line-height:20px}            .system-message .btn{display:inline-block;margin-right:10px;width:138px;height:2pc;border:1px solid #44a0e8;border-radius:30px;color:#44a0e8;text-align:center;font-size:1pc;line-height:2pc;margin-bottom:5px;}            .success .btn{border-color:#69bf4e;color:#69bf4e}            .error .btn{border-color:#ff8992;color:#ff8992}            .info .btn{border-color:#3498db;color:#3498db}            .copyright p{width:100%;color:#919191;text-align:center;font-size:10px}            .system-message .btn-grey{border-color:#bbb;color:#bbb}            .clearfix:after{clear:both;display:block;visibility:hidden;height:0;content:"."}            @media (max-width:768px){body {padding:20px 0;}}            @media (max-width:480px){.system-message h1{font-size:30px;}}                        
ThinkPHP中自定义错误、成功、异常提示页面的方法

ThinkPHP中自定义错误、成功、异常提示页面的方法

页面将在 <!-- 3 -->秒后自动<a id="href" href="">跳转

返回上一步 <a href="" class="btn btn-primary">立即跳转

(function () { var wait = document.getElementById('wait'), href = document.getElementById('href').href; var interval = setInterval(function () { var time = --wait.innerHTML; if (time <= 0) { location.href = href; clearInterval(interval); } }, 1000); })();

 效果如下:

2.jpg

推荐教程:《TP5》

以上就是ThinkPHP中自定义错误、成功、异常提示页面的方法的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/89636.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年11月18日 05:55:34
下一篇 2025年11月18日 06:33:21

相关推荐

发表回复

登录后才能评论
关注微信