Custom Error Page and Prompt Page Instances in ThinkPHP

  • 2021-08-05 09:26:11
  • OfStack

This article illustrates the method of customizing error page and prompt page in ThinkPHP. Share it for your reference. The specific implementation method is as follows:

Error page _ 404 when there are two methods in ThinkPHP ('Error Message', 'Address to Jump'); halt ('prompt information ');
Both functions can customize the error page and add it to the configuration file

'TMPL_EXCEPTION_FILE'=>'./Public/Tpl/error.html'

This will jump to this page every time.

Here's my custom error page

 In ( 3 ) Jump automatically after seconds, or click directly   Here   Jump   Stop 
$this->success(' Error message ',' Address of jump ( Best use U())', Time );
$this->error();

The following is the prompt page for me to change ThinkPHP

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title> Prompt message - ThinkPHP</title>  
 
<style type="text/css">  
body { font: 75% Arail; text-align: center; }  
#notice { width: 300px; background: #FFF; border: 1px solid #BBB; background: #EEE; padding: 3px;  
position: absolute; left: 50%; top: 50%; margin-left: -155px; margin-top: -100px; }  
#notice div { background: #FFF; padding: 30px 0 20px; font-size: 1.2em; font-weight:bold }  
#notice p { background: #FFF; margin: 0; padding: 0 0 20px; }  
a { color: #f00} a:hover { text-decoration: none; }  
</style>  
</head>  
<body>  
<div id="notice">  
 
<present name="message">  
<p style="font: italic bold 2cm cursive,serif; color:green">  
ok   
</p>  
<div class="success" style="width:100%;text-align:left;padding-left:10px;padding-right:10px">  
<?php echo($message); ?>  
</div>  
<else/>  
<p style="font: italic bold 2cm cursive,serif; color:red">  
×   
</p>  
<div class="error" style="width:100%;text-align:left;padding-left:10px;padding-right:10px">  
</div>  
</present>
<p>  
In ( <span id="sec" style="color:blue;font-weight:bold"><?php echo($waitSecond); ?></span> ) Jump automatically after seconds, or click directly <a href="javascript : window.location='<?php echo($jumpUrl); ?>'"> Here </a> Jump <br>  
<span style="display:block;text-decoration:underline;cursor:pointer;line-height:25px" onclick="stop(this)"> Stop </span>  
</p>  
</div>  
<script>  
var seco=document.getElementByIdx_x("sec");  
var time=<?php echo($waitSecond); ?>;  
var tt=setInterval(function(){  
time--;  
seco.innerHTML=time;  
if(time<=0){  
window.location='<?php echo($jumpUrl); ?>' 
return;  
}  
}, 1000);  
function stop(obj){  
clearInterval(tt);  
obj.style.display="none";  
}  
</script>  
</body>  
</html>

I hope this article is helpful to everyone's ThinkPHP framework programming.


Related articles: