Thinkphp5.1 example of frame page Jump and modification of jump page template

Time:2019-12-14

In this paper, the example of thinkphp5.1 frame page Jump and modify the jump page template. To share with you for your reference, as follows:

Corresponding controller creates corresponding HTML

For example:

Admin (module) / LPP (controller) / index (method)

Corresponding HTML file:

view->lpp->index.html

1. Index.html layout

<form action="{:url('bbc')}" method="post">
<h3>User login interface</h3>
<p>UserName:
<input name="username" type="text"/>
 </p>
<p>PassWord:
  <input name="password" type="password"/>
</p>
<p>
  < input type = "submit" value = "login" / >
  < input type = "reset" value = "Cancel" >
</p>
</form>

2. Index () method:

public function index(){
  //Load page
  return view();
}

Index.html the method of jump processing data after inputting content

//Methods of post jump processing
public function bbc(){
  //Accept data (not visible in URL)
  $username = $_POST['username'];
  $password = $_POST['password'];
  //Judge the input information
  if ($username == 'admin' && $password == 'admin'){
    //If the jump address is not set, the previous page will be returned by default
    $this - > success ('login succeeded! ','Index/diaoyong');
  }else{
    $this - > error ('wrong information! ).
  }
}

3. Modify the template of the jump page

A. find the setting template location in the app.php file

B. file directory

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

C. data from the jump method to the template page

Echo $code. "< HR >"; -- returned status code 1 succeeded 0 failed
Echo $MSG. "< HR >"; -- prompt message of the page
Echo $wait. "< HR >"; -- waiting time
Echo $URL. "< HR >"; -- set the jump page to return to the previous page by default
Echo $data. "< HR >"; -- data returned by the user

D. skip to page template modification

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


<?php switch ($code) {?>
  <?php case 1:?>
  <img src="/static/xiao.jpg" alt="">
  <h1>:)</h1>
  <p><?php echo(strip_tags($msg));?></p>
  <?php break;?>
  <?php case 0:?>
  <img src="/static/ku.jpg" alt="">
  <h1>:(</h1>
  <p><?php echo(strip_tags($msg));?></p>
  <?php break;?>
<?php } ?>

Picture location: / static / xiao.jpg and / static / ku.jpg

E. self built template

success.tpl

error.tpl

For example: error.tpl

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8" />
< title > error! </title>
<link rel="stylesheet" href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="external nofollow" >
</head>
<body>
    <div>
    <div></div>
    <div>
    <div>
      <div>
        <?php echo $msg?>
      </div>
      <div>
        <img src="/static/ku.jpg" alt="" width="100%">
      </div>
      <div>
        <p>
          Page auto < a href = "< PHP echo ($URL);? > rel =" external nofollow "> jump < / a > wait time: < b > < 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>

Picture preview:

For more information about ThinkPHP, readers who are interested in it can see the following topics: introduction to ThinkPHP, summary of operation skills of ThinkPHP template, summary of common methods of ThinkPHP, introduction to CodeIgniter, advanced tutorial of CI (CodeIgniter) framework, introduction to Zend framework and technical summary of PHP template.

I hope that this article will be helpful for you to design your PHP program based on the think PHP framework.

Recommended Today

[Redis5 source code learning] analysis of the randomkey part of redis command

baiyan Command syntax Command meaning: randomly return a key from the currently selected databaseCommand format: RANDOMKEY Command actual combat: 127.0.0.1:6379> keys * 1) “kkk” 2) “key1” 127.0.0.1:6379> randomkey “key1” 127.0.0.1:6379> randomkey “kkk” Return value: random key; nil if database is empty Source code analysis Main process The processing function corresponding to the keys command is […]