ThinkPHP修改成功和失败的模板页面:
一、修改默认文件
1、找到目录文件:
C:\wamp64\www\tp5\thinkphp\library\traits\controlle\Jump.php
2、找到
<?php switch ($code) {?> <?php case 1:?> <h1>:)</h1> <p class="success"><?php echo(strip_tags($msg));?></p> <?php break;?> <?php case 0:?> <h1>:(</h1> <p class="error"><?php echo(strip_tags($msg));?></p> <?php break;?> <?php } ?>
3、图片目录
public/static
4、替换笑脸和哭脸
<h1><img src="/static/xiao.png"></h1>
<h1><img src="/static/ku.png"></h1>
二、自定义跳转模板
1、修改应用配置文件
// 默认跳转页面对应的模板文件 'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl', 'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
// 默认跳转页面对应的模板文件 'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'success.tpl', 'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'error.tpl',
2、修改Jump.php文件
<?php switch ($code) {?> <?php case 1:?> <!-- 代表成功 --> <!-- <h1>:)</h1> --> <img src="/static/xiao.jpg" alt="" /> <p class="success"><?php echo(strip_tags($msg));?></p> <?php break;?> <?php case 0:?> <!-- 代表失败 --> <!-- <h1>:(</h1> --> <img src="/static/ku.jpg" alt="" /> <p class="error"><?php echo(strip_tags($msg));?></p> <?php break;?> <?php } ?>
3、自定义书写跳转页面
在系统模板目录下 (C:\AppServ\www\tp5\thinkphp\tpl) 新建 success.php 和error.php
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="/static/bs/css/bootstrap.min.css"> </head> <body> <div class="container"> <div class="col-md-4"></div> <div class="col-md-4"> <div class="panel panel-primary"> <div class="panel-heading"> <?php echo $msg?> </div> <div class="panel-body"> <img src="/static/xiao.jpg" width="100%" alt=""> <p class="jump"> 页面自动 <a id="href" href="<?php echo($url);?>">跳转</a> 等待时间: <b id="wait"><?php echo($wait);?></b> </p> </div> </div> </div> </div> </body> <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> </html>