ThinkPHP version 3.1.3 空模块 和 空操作

当用户访问不存在的模块或者是操作时,我们需要处理这个抛出的异常

来看一下,目录结构:

新建控制器,EmptyAction.class.php ,在ThinkPHP中,如果用户访问一个不存在的模块,它会去找EmptyAction.class.php 这个控制器 ,如果访问空方法,那么会去找该控制器下的 _empty() 方法;

我利用这个空操作,制作了一个"页面不存在"的方法,途中的jum()方法就是,在用户没找到模块或者是没有找到方法时,跳转的“自定义函数”;

贴一下我的自定义的jump()函数,

/** 页面自动跳转方法
 *  $time: 多少秒后开始跳转,默认3秒
 *  $url: 跳转的路径
 *  $msg: 提示信息(默认操作成功)
 *  $urlName: 所给网址的名称
 */
function jump($url, $urlName, $msg=':) 操作成功', $time=3) {
    $url = preg_match("/^(?:http\:\/\/|https\:\/\/)/", CI($url)) ? $url : 'http://'.$url;
    $pubPath = '/'.PUBLIC_PATH;
    return <<<EOT
    <!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" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <title>正在为您跳转到{$urlName}</title>
    </head>
    <body>
        <div style='width:594px;height:290px;margin:auto;margin-top:40px;border:4px solid #eee;border-radius:4px;'>
            <img style='border:none;padding:5px;' src="{$pubPath}Img/404.jpg" width='584' height='280' />
        </div>
        <div style='width:584px;height:30px;line-height:30px;margin:auto;font-weight:700;margin-top:10px;font-family:consolas,微软雅黑;'>
            <span>{$msg},<span style='color:red' id='wait'>{$time}</span>&nbsp;秒后跳转到<a style='color:#0F2299' href="{$url}" id='href'>{$urlName}</a></span><span>若页面没有跳转,请点<a style='color:#0F2299' href="{$url}" id='href'>这里</a></span>
        </div>
        <script type='text/javascript'>
            (function(){
                var time = document.getElementById('wait').innerHTML,
                    href = "{$url}";
                var t = setInterval(function () {
                    --time;
                    if (time>=0) {
                        document.getElementById('wait').innerHTML = time;
                    } else {
                        clearInterval(t);
                        window.location.href = href;
                    }
                },1000);
            })();
        </script>
    </body>
    </html>
EOT;
}

 

posted @ 2014-09-04 17:36  Zell~Dincht  阅读(639)  评论(0编辑  收藏  举报