Home >Backend Development >PHP Tutorial >Custom error pages and prompt pages in ThinkPHP
This article mainly introduces the method of customizing error pages and prompt pages in ThinkPHP. It describes in detail the method of implementing customized error prompts and jump pages in ThinkPHP in the form of a complete example. It is a very common practical skill. Friends in need can refer to
. This article describes how to customize error pages and prompt pages in ThinkPHP. Share it with everyone for your reference. The specific implementation method is as follows:
When there are two methods in ThinkPHP, the error page is prompted_404('error message','jump address');halt('prompt message');
This Both functions can customize the error page by adding
to the configuration file. Copy the code . The code is as follows:
'TMPL_EXCEPTION_FILE'=>'./Public/Tpl/error.html'
This will jump to this page every time.
The following is my customized error page
Copy code The code is as follows:
Automatically jump after (3) seconds, or Click here to jump to stop
$this->success('错误信息','跳转的地址(最好用U())',时间); $this->error();
The following is the prompt page I changed in ThinkPHP
Copy code The code is as follows:
<!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>提示消息 - 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 p { 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> <p id="notice"> <present name="message"> <p style="font: italic bold 2cm cursive,serif; color:green"> ok </p> <p class="success" style="width:100%;text-align:left;padding-left:10px;padding-right:10px"> <?php echo($message); ?> </p> <else/> <p style="font: italic bold 2cm cursive,serif; color:red"> × </p> <p class="error" style="width:100%;text-align:left;padding-left:10px;padding-right:10px"> </p> </present> <p> 在( <span id="sec" style="color:blue;font-weight:bold"><?php echo($waitSecond); ?></span> )秒后自动跳转,或直接点击 <a href="javascript:window.location='<?php echo($jumpUrl); ?>'">这里</a> 跳转<br> <span style="display:block;text-decoration:underline;cursor:pointer;line-height:25px" onclick="stop(this)">停止</span> </p> </p> <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>
Related Recommended:
How to set up a custom directory structure in ThinkPHP
##
The above is the detailed content of Custom error pages and prompt pages in ThinkPHP. For more information, please follow other related articles on the PHP Chinese website!