首页 > 语言 > PHP > 正文

ThinkPHP5.1框架页面跳转及修改跳转页面模版示例

2024-05-05 00:08:53
字体:
来源:转载
供稿:网友

本文实例讲述了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"  <h1>:)</h1>  <p class="success"><?php echo(strip_tags($msg));?></p>  <?php break;?>  <?php case 0:?>  <img src="/static/ku.jpg"  <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"      </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>

图片预览:

ThinkPHP,页面跳转,跳转页面模版

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。


注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选