ThinkPHP框架下成功、错误模板页面修改
2017-08-25 11:19
309 查看
一、ThinkPHP3.2环境下
默认的模板路径为TP目录下的 ThinkPHP/Tpl/dispatch_jump.tpl文件。修改配置文件
在应用目录下的/Common/Conf/config.php中添加/* 错误页面模板 */ 'TMPL_ACTION_ERROR' => 'Public/dispatch_jump', // 默认错误跳转对应的模板文件' 'TMPL_ACTION_SUCCESS' => 'Public/dispatch_jump', // 默认成功跳转对应的模板文件' //'TMPL_EXCEPTION_FILE' => 'Public/exception.html',// 异常页面的模板文件
添加模板
然后在应用前台或后台中添加新的模板文件(dispatch_jump.html)。举个例子
在我的环境中,前台的修改是在/Home/View/Public目录下,添加dispatch_jump.html文件。dispatch_jump.html内容如下:
<html lang="zh-CN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>跳转提示</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style type="text/css"> *{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;}} </style> </head> <body> <div class="system-message error"> <?php if(isset($message)){ ?> <div class="image"> <img src="http://cdn.demo.fastadmin.net/assets/img/success.svg" alt="" width="150" /> </div> <h1> <?php echo $message; }else{ ?> <div class="image"> <img src="http://cdn.demo.fastadmin.net/assets/img/error.svg" alt="" width="150" /> </div> <h1> <?php echo $error; }?></h1> <p class="jump"> 页面将在 <span id="wait"><?php echo($waitSecond); ?></span><!-- <span id="wait">3</span> -->秒后自动<a id="href" href="<?php echo($jumpUrl); ?>">跳转</a> </p> <p class="clearfix"> <a href="javascript:history.go(-1);" class="btn btn-grey">返回上一步</a> <a href="<?php echo($jumpUrl); ?>" class="btn btn-primary">立即跳转</a> </p> </div> <script type="text/javascript"> (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); })(); </script> </body> </html>
二、ThinkPHP5.0环境下
思路基本和TP3一致修改配置文件
在你的配置文件中,添加模板文件路径'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'my_dispatch_jump.tpl', 'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'my_dispatch_jump.tpl', //'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'my_think_exception.tpl',
我使用的是默认的路径,但是添加了一个新的模板文件’my_dispatch_jump.tpl’
添加新模板到配置路径下
将’my_dispatch_jump.tpl’添加到默认模板路径/thinkphp/tpl路径下模板例子
TP5.0的模板和TP3.2只有些许不同,这里同样给出我的模板<html lang="zh-CN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>跳转提示</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style type="text/css"> *{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;}} </style> </head> <body> <div class="system-message"> <?php switch ($code){ case 1: ?> <div class="image"> <img src="http://cdn.demo.fastadmin.net/assets/img/success.svg" alt="" width="150" /> </div> <h1> <?php echo (strip_tags($msg)); break; case 0: ?> <div class="image"> <img src="http://cdn.demo.fastadmin.net/assets/img/error.svg" alt="" width="150" /> </div> <h1> <?php echo (strip_tags($msg)); break; } ?> </h1> <p class="jump"> 页面将在 <span id="wait"><?php echo($wait); ?></span><!-- <span id="wait">3</span> -->秒后自动<a id="href" href="<?php echo($url); ?>">跳转</a> </p> <p class="clearfix"> <a href="javascript:history.go(-1);" class="btn btn-grey">返回上一步</a> <a href="<?php echo($url); ?>" class="btn btn-primary">立即跳转</a> </p> </div> <script type="text/javascript"> (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); })(); </script> </body> </html>
相关文章推荐
- ThinkPHP3.1.x修改成功与失败跳转页面的方法
- ThinkPHP自定义错误页面、成功页面及异常页面
- 【ThinkPHP】修改ThinkPHP3.1.x成功与失败的跳转页面
- ThinkPhp5框架查看页面基本信息,执行文件,流程,错误,sql,调试
- ThinkPHP5的配置之修改默认跳转成功和失败页面
- thinkPHP5 错误页面修改
- ThinkPHP第五天(提交类型判定常量IS_POST等,错误页面种类,Model实例化方式,模板中使用函数,foreach循环,模板中.语法配置)
- jsp页面中修改html元素内容关于单双引号的错误笔记
- [页面模板框架对比] Apache Tiles VS Sitemesh
- STS 2.9创建spring模板项目编译错误修改
- ThinkPHP中自定义错误页面和提示页面实例
- 修改用户信息的时候,使用Servlet对新的数据和数据库的数据进行对比,修改成功实现页面的弹窗和页面的跳转
- thinkphp框架开启页面gzip压缩
- MyEclipse:修改MyEclipse开发工具中的页面模板(JSP和HTML等)
- SSM框架,使用getBean可以成功获取,但是使用AutoWired注解出现错误
- 动态修改ThinkPHP的模板主题
- discuz 注册和登陆成功后跳转页面修改
- 学习ThinkPHP3.2.2:video15,模板标签中的空格导致输出内容错误
- 普通页面保存了,如何修改成模板
- ThinkPHP实现在可视化后台管理永久修改前端视图页面的方法