ThinkPHP Jump Page success and error Template Example Tutorial

  • 2021-07-09 07:20:40
  • OfStack

This paper explains the implementation method of view and controller corresponding to success and error methods in ThinkPHP jump page with examples. Through this example tutorial, readers can better master the use of success and error methods.

First, in the controller, you can use the following code:


<?php
//  This document is automatically generated for test run only 
class IndexAction extends Action
{
 /**
 +----------------------------------------------------------
 *  Default action 
 +----------------------------------------------------------
 */
 public function index()
 {
  $this->assign("title"," Water purifier ");
  $User = M("User"); //  Instantiation User Object 
  $result = $User->add($data);
  if ($result){
  //  Set the jump page address after success   The default return page is $_SERVER["HTTP_REFERER"]
  $this->assign("jumpUrl","index");
  $this->success(" New success! ");
  }else{
  //  The default jump page for the error page is to return to the 1 Page   You can usually not set the 
   $this->error(" New error! ");
  }
  $this->display();
 }
}
?>

success. html Page Location: Tpl\ default\ Public\ success.html


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="200; url='{$Url}'" />
<title> Success prompt information </title>
</head>
<body>
<table width="500" border="1" align="center" cellpadding="3" cellspacing="0">
 <tr>
 <th align="center" bgcolor="#cccccc"> Success message prompt </th>
 </tr>
 <tr>
 <td>{$message}<br />
   Successfully processed header information: {$msgTitle}<br />
  <present name="message">
   Customize success information: {$message}<br />
  </present>
  <present name="error">
   Custom error message: {$error}<br />
  </present>
   Jump page path: {$jumpUrl}<br />
   Stay time: {$waitSecond}<br />
  2 Seconds to return to the specified page! <br />
   If the browser cannot jump, <a href="__ROOT__/{$jumpUrl}" rel="external nofollow" rel="external nofollow" > Please click here </a> . </td>
 </tr>
</table>
</body>
</html> 

error page location: Tpl\ default\ Public\ success. html


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="2; url='{$Url}'" />
<title> Success prompt information </title>
</head>
<body>
<table width="400" border="1" align="center" cellpadding="3" cellspacing="0">
 <tr>
 <th align="center" bgcolor="#cccccc"> Error message prompt </th>
 </tr>
 <tr>
 <td>{$message}<br />
   Successfully processed header information: {$msgTitle}<br />
  <present name="message">
   Customize success information: {$message}<br />
  </present>
  <present name="error">
   Custom error message: {$error}<br />
  </present>
   Jump page path: {$jumpUrl}<br />
   Stay time: {$waitSecond}<br />
  2 Seconds to return to the specified page! <br />
   If the browser cannot jump, <a href="__ROOT__/{$jumpUrl}" rel="external nofollow" rel="external nofollow" > Please click here </a> . </td>
 </tr>
</table>
</body>
</html>

Both Success and error methods have templates and can be set. The default settings are Public: success and Public: error. Template files can use template tags and can use the following template variables:

$msgTitle: Action title
$message: Page prompt information
$status: Operation status 1 means success 0 means failure. Specific rules can also be defined by the project itself
$waitSecond: Jump wait time unit is good
$jumpUrl: Jump page address
If AJAX is submitted, the success and error methods call the ajaxReturn method to return information

For more readers interested in thinkPHP related contents, please check the topics of this site: "ThinkPHP Introduction Tutorial", "thinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "smarty Template Introduction Basic Tutorial" and "PHP Template Technology Summary".

I hope this article is helpful to PHP programming based on ThinkPHP framework.


Related articles: