ThinkPHP中自訂錯誤頁面和提示頁面執行個體_php執行個體

來源:互聯網
上載者:User

本文執行個體講述了ThinkPHP中自訂錯誤頁面和提示頁面的方法。分享給大家供大家參考。具體實現方法如下:

在ThinkPHP中有兩個方法時提示錯誤頁面 _404('錯誤資訊','跳轉的地址');halt('提示資訊');
這兩個函數都可以自訂錯誤頁面在設定檔中加

複製代碼 代碼如下:
'TMPL_EXCEPTION_FILE'=>'./Public/Tpl/error.html'

這樣每次就會跳轉到這個頁面。

下面是我定製的錯誤頁面

複製代碼 代碼如下:
在( 3 )秒後自動跳轉,或直接點擊 這裡 跳轉 停止

$this->success('錯誤資訊','跳轉的地址(最好用U())',時間);

$this->error();

下面是我改變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>提示訊息 - 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>  
在( <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>  
</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>

希望本文所述對大家的ThinkPHP架構程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.