溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ThinkPHP中如何自定義錯(cuò)誤、成功、異常提示頁面

發(fā)布時(shí)間:2021-01-16 10:51:56 來源:億速云 閱讀:393 作者:小新 欄目:編程語言

這篇文章給大家分享的是有關(guān)ThinkPHP中如何自定義錯(cuò)誤、成功、異常提示頁面的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

ThinkPHP提供了自帶的錯(cuò)誤提示頁面,但是并不美觀,提示信息顯示如下:

ThinkPHP中如何自定義錯(cuò)誤、成功、異常提示頁面

我們?nèi)绻胍鼡Q提示頁面應(yīng)該怎么做呢?

以ThinkPHP3.2為例:

在應(yīng)用配置文件(應(yīng)用文件目錄/Common/Conf/config.php)中添加:

/* 錯(cuò)誤頁面模板 */
'TMPL_ACTION_ERROR'     =>  'Public/dispatch_jump.html', // 默認(rèn)錯(cuò)誤跳轉(zhuǎn)對應(yīng)的模板文件'
'TMPL_ACTION_SUCCESS'   =>  'Public/dispatch_jump.html', // 默認(rèn)成功跳轉(zhuǎn)對應(yīng)的模板文件'
//'TMPL_EXCEPTION_FILE'   =>  'Public/exception.html',// 異常頁面的模板文件

然后我是在項(xiàng)目公共文件(項(xiàng)目目錄/Public)中新建了dispatch_jump.html,模板內(nèi)容如下:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>跳轉(zhuǎn)提示</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style type="text/css">
            *{box-sizing:border-box;margin:0;padding:0;font-family:Lantinghei SC,Open Sans,Arial,Hiragino Sans GB,Microsoft YaHei,"微軟雅黑",STHeiti,WenQuanYi Micro Hei,SimSun,sans-serif;-webkit-font-smoothing:antialiased}
            body{padding:70px 0;background:#edf1f4;font-weight:400;font-size:1pc;-webkit-text-size-adjust:none;color:#333}
            a{outline:0;color:#3498db;text-decoration:none;cursor:pointer}
            .system-message{margin:20px 5%;padding:40px 20px;background:#fff;box-shadow:1px 1px 1px hsla(0,0%,39%,.1);text-align:center}
            .system-message h2{margin:0;margin-bottom:9pt;color:#444;font-weight:400;font-size:40px}
            .system-message .jump,.system-message .image{margin:20px 0;padding:0;padding:10px 0;font-weight:400}
            .system-message .jump{font-size:14px}
            .system-message .jump a{color:#333}
            .system-message p{font-size:9pt;line-height:20px}
            .system-message .btn{display:inline-block;margin-right:10px;width:138px;height:2pc;border:1px solid #44a0e8;border-radius:30px;color:#44a0e8;text-align:center;font-size:1pc;line-height:2pc;margin-bottom:5px;}
            .success .btn{border-color:#69bf4e;color:#69bf4e}
            .error .btn{border-color:#ff8992;color:#ff8992}
            .info .btn{border-color:#3498db;color:#3498db}
            .copyright p{width:100%;color:#919191;text-align:center;font-size:10px}
            .system-message .btn-grey{border-color:#bbb;color:#bbb}
            .clearfix:after{clear:both;display:block;visibility:hidden;height:0;content:"."}
            @media (max-width:768px){body {padding:20px 0;}}
            @media (max-width:480px){.system-message h2{font-size:30px;}}
        </style>
    </head>
    <body>
        <div class="system-message error">
            <?php
                if(isset($message)){
            ?>
            <div class="image">
                <img src="http://cdn.demo.fastadmin.net/assets/img/success.svg" alt="" width="150" />
            </div>
            <h2>
            <?php
                echo $message;
                }else{
            ?>
             <div class="image">
                <img src="http://cdn.demo.fastadmin.net/assets/img/error.svg" alt="" width="150" />
            </div>
            <h2>
            <?php
                echo $error;
            }?></h2>
            <p class="jump">
                頁面將在 <span id="wait"><?php echo($waitSecond); ?></span><!-- <span id="wait">3</span>  -->秒后自動(dòng)<a id="href" href="<?php echo($jumpUrl); ?>">跳轉(zhuǎn)</a>
            </p>
            <p class="clearfix">
                <a href="javascript:history.go(-1);" class="btn btn-grey">返回上一步</a>
                <a href="<?php echo($jumpUrl); ?>" class="btn btn-primary">立即跳轉(zhuǎn)</a>
            </p>
        </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>

效果如下:

ThinkPHP中如何自定義錯(cuò)誤、成功、異常提示頁面

感謝各位的閱讀!關(guān)于“ThinkPHP中如何自定義錯(cuò)誤、成功、異常提示頁面”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI