tp5 修改自带success或error跳转模板页面
我们在使用tp5或者tp3.2的时候,用的成功或者失败跳转提示页面一般是用框架的。在后续开发过程中,根据实际项目需要,也是可以更改的,在此分享一个自用的模板。
首先是看一下tp框架自带的跳转模板页面,以tp5为例
在config.php中,我们可以看到,success或error都是用的同一个页面,

在默认的情况下,生成的效果图就是大家经常看到的那个"笑脸"或"哭脸"
失败:
,成功:
修改之后的效果图,是这样的
失败:
,成功:
下面的是修改之后的dispatch_jump.tpl的源代码:
1 1 {__NOLAYOUT__}<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 3 <head> 4 4 <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" /> 5 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 6 6 <title>跳转提示</title> 7 7 <?php if(isMobile()==true){?> 8 8 <style type="text/css"> 9 9 body, h1, h2, p,dl,dd,dt{margin: 0;padding: 0;font: 15px/1.5 微软雅黑,tahoma,arial;} 1010 body{background:#efefef;} 1111 h1, h2, h3, h4, h5, h6 {font-size: 100%;cursor:default;} 1212 ul, ol {list-style: none outside none;} 1313 a {text-decoration: none;color:#447BC4} 1414 a:hover {text-decoration: underline;} 1515 .ip-attack{width:100%; margin:200px auto 0;} 1616 .ip-attack dl{ background:#fff; padding:30px; border-radius:10px;border: 1px solid #CDCDCD;-webkit-box-shadow: 0 0 8px #CDCDCD;-moz-box-shadow: 0 0 8px #cdcdcd;box-shadow: 0 0 8px #CDCDCD;} 1717 .ip-attack dt{text-align:center;} 1818 .ip-attack dd{font-size:16px; color:#333; text-align:center;} 1919 .tips{text-align:center; font-size:14px; line-height:50px; color:#999;} 2020 </style> 2121 <?php }else{ ?> 2222 <style type="text/css"> 2323 body, h1, h2, p,dl,dd,dt{margin: 0;padding: 0;font: 15px/1.5 微软雅黑,tahoma,arial;} 2424 body{background:#efefef;} 2525 h1, h2, h3, h4, h5, h6 {font-size: 100%;cursor:default;} 2626 ul, ol {list-style: none outside none;} 2727 a {text-decoration: none;color:#447BC4} 2828 a:hover {text-decoration: underline;} 2929 .ip-attack{width:600px; margin:200px auto 0;} 3030 .ip-attack dl{ background:#fff; padding:30px; border-radius:10px;border: 1px solid #CDCDCD;-webkit-box-shadow: 0 0 8px #CDCDCD;-moz-box-shadow: 0 0 8px #cdcdcd;box-shadow: 0 0 8px #CDCDCD;} 3131 .ip-attack dt{text-align:center;} 3232 .ip-attack dd{font-size:16px; color:#333; text-align:center;} 3333 .tips{text-align:center; font-size:14px; line-height:50px; color:#999;} 3434 </style> 3535 <?php }?> 3636 3737 </head> 3838 <body> 3939 <div class="ip-attack"><dl> 4040 <if condition="$code eq 1" > 4141 <dt style="color: green"><?php echo(strip_tags($msg));?></dt> 4242 <else/> 4343 <dt style="color: red"><?php echo(strip_tags($msg));?></dt> 4444 </if> 4545 4646 <br> 4747 <dt> 4848 页面自动 <a id="href" href="<?php echo($url);?>">跳转</a> 等待时间: <b id="wait"><?php echo($wait);?></b> 4949 </dt></dl> 5050 </div> 5151 <script type="text/javascript"> 5252 (function(){ 5353 var wait = document.getElementById('wait'), 5454 href = document.getElementById('href').href; 5555 var interval = setInterval(function(){ 5656 var time = --wait.innerHTML; 5757 if(time <= 0) { 5858 location.href = href; 5959 clearInterval(interval); 6060 }; 6161 }, 1000); 6262 })(); 6363 </script> 6464 </body> 6565 </html>
而且,对于移动端,也做了适配,下面是判断是否是移动端的js方法
1 1 /** 2 2 * 功能:是否是移动端 3 3 * 4 4 * User: cyf 5 5 * Time: 2018/7/3 0003 11:01 6 6 * @return bool 7 7 */ 8 8 function isMobile() 9 9 { 1010 if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) 1111 { 1212 return true; 1313 } 1414 if (isset ($_SERVER['HTTP_VIA'])) 1515 { 1616 return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false; 1717 } 1818 if (isset ($_SERVER['HTTP_USER_AGENT'])) 1919 { 2020 $clientkeywords = array ('nokia', 2121 'sony', 2222 'ericsson', 2323 'mot', 2424 'samsung', 2525 'htc', 2626 'sgh', 2727 'lg', 2828 'sharp', 2929 'sie-', 3030 'philips', 3131 'panasonic', 3232 'alcatel', 3333 'lenovo', 3434 'iphone', 3535 'ipod', 3636 'blackberry', 3737 'meizu', 3838 'android', 3939 'netfront', 4040 'symbian', 4141 'ucweb', 4242 'windowsce', 4343 'palm', 4444 'operamini', 4545 'operamobi', 4646 'openwave', 4747 'nexusone', 4848 'cldc', 4949 'midp', 5050 'wap', 5151 'mobile' 5252 ); 5353 if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) 5454 { 5555 return true; 5656 } 5757 } 5858 if (isset ($_SERVER['HTTP_ACCEPT'])) 5959 { 6060 if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) 6161 { 6262 return true; 6363 } 6464 } 6565 return false; 6666 }