success和error方法都可以对应的模板

success和error方法都可以对应的模板,默认两个方法对应的模板是框架自带的跳转模板
dispatch_jump.tpl:
//默认错误跳转对应的模板文件
'TMPL_ACTION_ERROR' => THINK_PATH . 'Tpl/dispatch_jump.tpl',
//默认成功跳转对应的模板文件
'TMPL_ACTION_SUCCESS' => THINK_PATH . 'Tpl/dispatch_jump.tpl',

D:\LearnWebDevelop\php\thinkphp_3.2.3_full\Application\Home\Controller\BlogController.class.php

    // http://localhost/thinkphp323/index.php/Home/Blog/result/id/5
    public function result($id){
        if((int)$id > 5){
            // 成功后跳转到新闻列表页面
            $this->success('新增成功,即将返回列表页面', '8');
        } else {
            // 错误页面的默认跳转页面是返回前一页,通常不需要设置
            $this->error('新增失败','4');
        }
    }

D:\LearnWebDevelop\php\thinkphp_3.2.3_full\Application\Home\Conf\config.php

<?php
return array(
//默认错误跳转对应的模板文件
'TMPL_ACTION_ERROR' => 'error_jump',
//默认成功跳转对应的模板文件
'TMPL_ACTION_SUCCESS' => 'success_jump',

D:\LearnWebDevelop\php\thinkphp_3.2.3_full\Application\Home\View\Blog\error_jump.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<p>Error!</p>
<div class="system-message">
<?php if(isset($message)) {?>
<h1>:)</h1>
<p class="success"><?php echo($message); ?></p>
<?php }else{?>
<h1>:(</h1>
<p class="error"><?php echo($error); ?></p>
<?php }?>
<p class="detail"></p>
<p class="jump">
页面自动 <a id="href" href="<?php echo($jumpUrl); ?>">跳转</a> 等待时间: <b id="wait"><?php echo($waitSecond); ?></b>
</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>

D:\LearnWebDevelop\php\thinkphp_3.2.3_full\Application\Home\View\Blog\success_jump.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<p>Success!</p>
<div class="system-message">
<?php if(isset($message)) {?>
<h1>:)</h1>
<p class="success"><?php echo($message); ?></p>
<?php }else{?>
<h1>:(</h1>
<p class="error"><?php echo($error); ?></p>
<?php }?>
<p class="detail"></p>
<p class="jump">
页面自动 <a id="href" href="<?php echo($jumpUrl); ?>">跳转</a> 等待时间: <b id="wait"><?php echo($waitSecond); ?></b>
</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>

 

posted @ 2017-12-07 09:49  sky20080101  阅读(142)  评论(0)    收藏  举报