標籤:方法 預設 error -- utf-8 ext css innerhtml err
預設的thinkphp success及error的預設範本不是很好看,下面分享如何自訂success及error頁面,這裡用的是thinkphp 3.2.2版本
預設的thinkphp success及error的預設範本不是很好看,下面分享大家如何自訂success及error頁面,這裡用的是thinkphp 3.2.2版本
首先在設定檔中添加以下代碼(/Application/Admin/Conf/config.php)
//自訂success和error的提示頁面模板
‘TMPL_ACTION_SUCCESS‘=>‘Public:dispatch_jump‘,
‘TMPL_ACTION_ERROR‘=>‘Public:dispatch_jump‘,
這裡error和success是公用的一個模板檔案,代碼如下(/Application/Admin/View/Public/dispatch_jump.html)
<!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: 6px; } .message{width: 400px;height: 150px;margin:auto;border:1px solid #1B8F24;margin-top: 30px;} .head{width: 100%;height: 30px;background: rgb(222,245,194);text-align: center;padding-top: 5px;} .content{height: 120px;width: 100%;} .success ,.error{text-align: center;margin-top: 30px;} .jump{text-align: center;margin-top: 20px;} </style> </head> <body> <div class="message"> <div class="head"><span>Ace Admin提示資訊:</span></div> <div class="content"> <?php if(isset($message)) {?> <p class="success">:) <?php echo($message); ?></p> <?php }else{?> <p class="error">:( <?php echo($error); ?></p> <?php }?> <p class="detail"></p> <p class="jump"> <a id="href" href="<?php echo($jumpUrl); ?>">如果你的瀏覽器沒有自動跳轉,請點擊這裡...</a> <br /> 等待時間: <b id="wait"><?php echo($waitSecond); ?></b> </p> </div> </div> <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>
使用smarty模板來解析程式的方法
先把配置改一下
‘TMPL_ACTION_ERROR‘ => ‘Public:error‘,
‘TMPL_ACTION_SUCCESS‘ => ‘Public:success‘,
然後在VIEW檔案下建立一個Public檔案夾 建兩個html :success.html和error.html
把ThinkPHP/Tpl/dispatch_jump.tpl的內容複寫過來
刪除和替換裡面的所有php標籤,因為smarty是不認<?php ?>這玩意的
只要改成smarty認的標籤就可以了。
比如你找到<?php echo($jumpUrl); ?>這個,我們把他替換成{$jumpUrl}就可以了,其他以此類推。
ThinkPHP3.2.2自訂success及error跳轉頁面