溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ThinkPHP5.1框架頁面跳轉(zhuǎn)及修改跳轉(zhuǎn)頁面模版的示例分析

發(fā)布時(shí)間:2021-07-23 09:17:33 來源:億速云 閱讀:150 作者:小新 欄目:開發(fā)技術(shù)

小編給大家分享一下ThinkPHP5.1框架頁面跳轉(zhuǎn)及修改跳轉(zhuǎn)頁面模版的示例分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

具體如下:

對應(yīng)的控制器 創(chuàng)建對應(yīng)的HTML

比如:

admin(模塊)/lpp(控制器)/index(方法)

對應(yīng)的html文件:

view->lpp->index.html

1.index.html布局

<form action="{:url('bbc')}" method="post">
<h4>用戶登錄界面</h4>
<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輸入內(nèi)容后跳轉(zhuǎn)處理數(shù)據(jù)的方法

//跳轉(zhuǎn)后處理的方法
public function bbc(){
  //接受數(shù)據(jù) (在URL中不可以被別人看見)
  $username = $_POST['username'];
  $password = $_POST['password'];
  //判斷輸入的信息
  if ($username == 'admin' && $password == 'admin'){
    //跳轉(zhuǎn)地址未設(shè)置時(shí),默認(rèn)返回上一個(gè)頁面
    $this->success('登錄成功!','Index/diaoyong');
  }else{
    $this->error('信息有誤!');
  }
}

3.修改跳轉(zhuǎn)頁面的模版

a、在app.php文件里面找到設(shè)置模版位置

b、文件目錄

C:\wamp\www\tp5\thinkphp\tpl\dispatch_jump.tpl

c、跳轉(zhuǎn)方法給模版頁面的數(shù)據(jù)

echo $code."<hr>"; --返回的狀態(tài)碼 1成功 0失敗
echo $msg."<hr>";  --頁面的提示信息
echo $wait."<hr>"; --等待的時(shí)間
echo $url."<hr>";  --制定跳轉(zhuǎn)頁面 默認(rèn)返回上一個(gè)頁面
echo $data."<hr>"; --用戶返回的數(shù)據(jù)

d、跳轉(zhuǎn)頁面模版修改

C:\wamp\www\tp5\thinkphp\tpl\dispatch_jump.tpl

<?php switch ($code) {?>
  <?php case 1:?>
  <img src="/static/xiao.jpg" >
  <h2>:)</h2>
  <p class="success"><?php echo(strip_tags($msg));?></p>
  <?php break;?>
  <?php case 0:?>
  <img src="/static/ku.jpg" >
  <h2>:(</h2>
  <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>錯(cuò)誤!</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"  width="100%">
      </div>
      <div class="panel-footer">
        <p class="jump">
          頁面自動 <a id="href" href="<?php echo($url);?>" rel="external nofollow" >跳轉(zhuǎn)</a> 等待時(shí)間: <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>

圖片預(yù)覽:

ThinkPHP5.1框架頁面跳轉(zhuǎn)及修改跳轉(zhuǎn)頁面模版的示例分析

以上是“ThinkPHP5.1框架頁面跳轉(zhuǎn)及修改跳轉(zhuǎn)頁面模版的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI