天天看點

關于如何改變thinkphp中自定義的成功界面、錯誤界面、異常界面

      我們在thinkphp的控制器Controller中調用$this->seccuss()、$this->error()、

$this->exception(),顯示的是成功界面,錯誤界面,異常界面。

      那麼,我們如何改變thinkphp中的這些界面呢?

      方法如下:

      第一步:如果我現在已經分組了,Admin分組中的配置檔案夾下config.php檔案中添加如下配置資訊:

<span style="font-size:18px;color:#009900;"><strong>'TMPL_ACTION_ERROR'     =>  MODULE_PATH.'View/Public/error.html', // 預設錯誤跳轉對應的模闆檔案
'TMPL_ACTION_SUCCESS'   =>  MODULE_PATH.'View/Public/success.html', // 預設成功跳轉對應的模闆檔案
'TMPL_EXCEPTION_FILE'   =>  MODULE_PATH.'View/Public/exception.html',// 異常頁面的模闆檔案</strong></span>
           

             第二步:在Admin分組中View目錄下建立Public檔案夾,并在裡面自定義error.html,success.html,exception.html。

     第三步:在這三個模闆中寫代碼,下面是一個success.html

<span style="font-size:18px;color:#009900;"><strong><?php
    if(C('LAYOUT_ON')) {
        echo '{__NOLAYOUT__}';
    }
?>
<!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>跳轉提示</title>
<style type="text/css">
*{ padding: 0; margin: 0; }
body{ background: #fff; font-family: '微軟雅黑'; color: #333; font-size: 16px;}
.system-message{ padding: 24px 48px; margin:0 auto; width:600px; position:relative; top:100px;}
.system-message h1{ font-size: 100px; font-weight: normal; line-height: 120px; margin-bottom: 12px; }
.system-message .jump{ padding-top: 10px}
.system-message .jump a{ color: #333;}
.system-message .success,.system-message .error{ line-height: 1.8em; font-size: 36px }
.system-message .detail{ font-size: 12px; line-height: 20px; margin-top: 12px; display:none}
</style>
</head>
<body>
<center>
<div class="system-message">
<?php if(isset($message)) {?>
<div style="float:left; height:250px; width:250px;">
<h1><img src="__PUBLIC__/Images/success.jpg"/></h1></div>
<div style="float:left; height:250px; width:300px; position:relative; top:50px;">
<p class="success"><?php echo($message); ?></p>
<?php }else{?>
<div style="float:left; height:250px; width:250px;">
<h1><img src="__PUBLIC__/Images/error.jpg"/></h1></div>
<div style="float:left; height:250px; width:300px; position:relative; top:50px;">
<p class="error"><?php echo($error); ?></p>
<?php }?>
<p class="detail"></p>
<p class="jump">
<b id="wait"><?php echo($waitSecond); ?></b>秒後自動跳轉</p>
<p class="jump">
如果沒有跳轉,點選<a id="href" href="<?php echo($jumpUrl); ?>" target="_blank" rel="external nofollow" >跳轉</a>
</p>
</p></div>
</div>
</center>
<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></strong></span>