本文实例讲述了ThinkPHP5.1框架页面跳转及修改跳转页面模版。分享给大家供大家参考,具体如下:
对应的控制器 创建对应的HTML
比如:
admin(模块)/lpp(控制器)/index(方法)
对应的html文件:
view->lpp->index.html
1.index.html布局
<form action="{:url('bbc')}" method="post">
<h3>用户登录界面</h3>
<p>UserName:
<input name="username" type="text" id="001"/>
 </p>
<p>PassWord:
 <input name="password" type="password" id="002"/>
</p>
<p>
 <input type="submit" value="登录"/>
 <input type="reset" value="取消">
</p>
</form>
2.index()方法:
public function index(){
 //加载页面
 return view();
}
index.html输入内容后跳转处理数据的方法
//跳转后处理的方法
public function bbc(){
 //接受数据 (在URL中不可以被别人看见)
 $username = $_POST['username'];
 $password = $_POST['password'];
 //判断输入的信息
 if ($username == 'admin' && $password == 'admin'){
 //跳转地址未设置时,默认返回上一个页面
 $this->success('登录成功!','Index/diaoyong');
 }else{
 $this->error('信息有误!');
 }
}
3.修改跳转页面的模版
a、在app.php文件里面找到设置模版位置
b、文件目录
C:\wamp\www\tp5\thinkphp\tpl\dispatch_jump.tpl
c、跳转方法给模版页面的数据
echo $code."<hr>"; --返回的状态码 1成功 0失败
echo $msg."<hr>"; --页面的提示信息
echo $wait."<hr>"; --等待的时间
echo $url."<hr>"; --制定跳转页面 默认返回上一个页面
echo $data."<hr>"; --用户返回的数据
d、跳转页面模版修改
C:\wamp\www\tp5\thinkphp\tpl\dispatch_jump.tpl
<?php switch ($code) {?>
 <?php case 1:?>
 <img src="/static/xiao.jpg" alt="">
 <h1>:)</h1>
 <p class="success"><?php echo(strip_tags($msg));?></p>
 <?php break;?>
 <?php case 0:?>
 <img src="/static/ku.jpg" alt="">
 <h1>:(</h1>
 <p class="error"><?php echo(strip_tags($msg));?></p>
 <?php break;?>
<?php } ?>
图片位置:/static/xiao.jpg 和 /static/ku.jpg
e、自建模版
success.tpl
error.tpl
例如:error.tpl
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8" />
<title>错误!</title>
<link rel="stylesheet" href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="external nofollow" >
</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/ku.jpg" alt="" width="100%">
 </div>
 <div class="panel-footer">
 <p class="jump">
 页面自动 <a id="href" href="<?php echo($url);?>" rel="external nofollow" >跳转</a> 等待时间: <b id="wait"><?php echo($wait);?></b>
 </p>
 </div>
 </div>
 </div>
 </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>
图片预览:
