$this->load->helper('url');
redirect('/login/form/', 'refresh');
通过发送HTTP头,命令客户端转向到您指定的URL。您既可以指定一个完整的URL,也可以对于站内内容,指定基于网站根目录的相对URL。本函数会自动根据您的配置文件,构造出完整的URL。
你可以设定第二个参数为 location 定位操作(默认)或者 refresh 刷新操作。定位操作比刷新操作执行速度快,但是在Windows服务器上有时会报错。可选的第3个参数允许你发送一个特定的HTTP请求返回码 - 举例来说这可以用来创建303请求重定向来服务于搜索引擎. 默认的请求返回码是302(临时重定向). 第3个参数 只使用于'location'重定向, 而不是用于'refresh'.
上面的是官方的解释;
但是TP的定时跳转就很不错
来一发:
代码修改如下 jump.php
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>跳转提示</title>
<style type="text/css">
*{ padding: 0; margin: 0; }
body{ background: #fff; font-family: "Microsoft Yahei","Helvetica Neue",Helvetica,Arial,sans-serif; color: #333; font-size: 16px; }
.system-message{ padding: 24px 48px; text-align: center; }
.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>
<div class="system-message">
<?php switch ($code) {?>
<?php case 1:?>
<h1>:)</h1>
<p class="success"><?php echo $msg;?></p>
<?php break;?>
<?php case 0:?>
<h1>:(</h1>
<p class="error"><?php echo $msg;?></p>
<?php break;?>
<?php } ?>
<p class="detail"></p>
<p class="jump">
页面自动 <a id="href" href="<?php echo($url);?>">跳转</a> 等待时间: <b id="wait"><?php echo($wait);?></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>
CI的控制器里来一发;
//跳转设置 $this->jump("index","success"); $this->load->view('jump',$data["jump"]);
private function jump($url,$msg){
$myjump=array(
'code' => 1,
'msg' => $msg,
'url' => $url,
'wait' => 3
);
return $myjump;
}
直接加载模板就可以了;
$data["jump"]=$this->jump("index","修改成功");
$this->load->view('jump',$data["jump"]);
效果与TP里竟然一样;
当然你也可以做两个函数,一个SUCCESS,一个ERROR;但是基本效果都是一样的