菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
328
0

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

原创
05/13 14:22
阅读数 219526

对应的控制器 创建对应的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 KSkUWVCVbbc(){
  //接受数据 (在URL中不可以被别人看见)
  $username = $_POST['username'];
  $password = KSkUWVCV$_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:?>
  KSkUWVCV<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>
    www.cppcns.com  <div class="panel-footer">
        <p class="jump">
          页面自动 <a id="href" href="<?php echo($url);?>" rel="external nofollow" >跳转</a> 等待时间: <b id="wait"><?php echo($wait);?>
        </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入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。

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

本文标题: ThinkPHP5.1框架页面跳转及修改跳转页面模版示例
本文地址: http://www.cppcns.com/wangluo/php/258431.html

发表评论

0/200
328 点赞
0 评论
收藏
为你推荐 换一批