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

 6031

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

5ec8e1dfb468b.jpg

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

以ThinkPHP3.2为例:

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

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

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

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>跳转提示</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <style type="text/css">
  8. *{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}
  9. body{padding:70px 0;background:#edf1f4;font-weight:400;font-size:1pc;-webkit-text-size-adjust:none;color:#333}
  10. a{outline:0;color:#3498db;text-decoration:none;cursor:pointer}
  11. .system-message{margin:20px 5%;padding:40px 20px;background:#fff;box-shadow:1px 1px 1px hsla(0,0%,39%,.1);text-align:center}
  12. .system-message h1{margin:0;margin-bottom:9pt;color:#444;font-weight:400;font-size:40px}
  13. .system-message .jump,.system-message .image{margin:20px 0;padding:0;padding:10px 0;font-weight:400}
  14. .system-message .jump{font-size:14px}
  15. .system-message .jump a{color:#333}
  16. .system-message p{font-size:9pt;line-height:20px}
  17. .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;}
  18. .success .btn{border-color:#69bf4e;color:#69bf4e}
  19. .error .btn{border-color:#ff8992;color:#ff8992}
  20. .info .btn{border-color:#3498db;color:#3498db}
  21. .copyright p{width:100%;color:#919191;text-align:center;font-size:10px}
  22. .system-message .btn-grey{border-color:#bbb;color:#bbb}
  23. .clearfix:after{clear:both;display:block;visibility:hidden;height:0;content:"."}
  24. @media (max-width:768px){body {padding:20px 0;}}
  25. @media (max-width:480px){.system-message h1{font-size:30px;}}
  26. </style>
  27. </head>
  28. <body>
  29. <div class="system-message error">
  30.     <?php
  31.         if(isset($message)){
  32.     ?>
  33.     <div class="image">
  34.         <img src="http://cdn.demo.fastadmin.net/assets/img/success.svg" alt="" width="150" />
  35.     </div>
  36.     <h1>
  37.     <?php
  38.         echo $message;
  39.         }else{
  40.     ?>
  41.     <div class="image">
  42.         <img src="http://cdn.demo.fastadmin.net/assets/img/error.svg" alt="" width="150" />
  43.     </div>
  44.     <h1>
  45.     <?php
  46.         echo $error;
  47.     }?></h1>
  48.     <p class="jump">
  49.         页面将在 <span id="wait"><?php echo($waitSecond); ?></span>秒后自动<a id="href" href="<?php echo($jumpUrl); ?>">跳转</a>
  50.     </p>
  51.     <p class="clearfix">
  52.         <a href="javascript:history.go(-1);" class="btn btn-grey">返回上一步</a>
  53.         <a href="<?php echo($jumpUrl); ?>" class="btn btn-primary">立即跳转</a>
  54.     </p>
  55. </div>
  56. <script type="text/javascript">
  57. (function () {
  58.     var wait = document.getElementById('wait'),
  59.             href = document.getElementById('href').href;
  60.     var interval = setInterval(function () {
  61.         var time = --wait.innerHTML;
  62.         if (time <= 0) {
  63.             location.href = href;
  64.             clearInterval(interval);
  65.         }
  66.     }, 1000);
  67. })();
  68. </script>
  69. </body>
  70. </html>

效果如下:

5ec8e2b099f5a.jpg

以上就是ThinkPHP中自定义错误、成功、异常提示页面的方法的详细内容。希望对大家有所帮助~~



本文网址:https://www.zztuku.com/detail-7789.html
站长图库 - ThinkPHP中自定义错误、成功、异常提示页面的方法
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐