Home > Backend Development > PHP Tutorial > TP框架的 redirect方法是怎么实现跳转的?一看源码,完全不能理解啊

TP框架的 redirect方法是怎么实现跳转的?一看源码,完全不能理解啊

WBOY
Release: 2016-06-13 12:02:15
Original
1124 people have browsed it

TP框架的 redirect方法是如何实现跳转的?一看源码,完全不能理解啊。。
protected function redirect($url,$params=array(),$delay=0,$msg='') {
$url = U($url,$params);
redirect($url,$delay,$msg);
}



先生存一个url,然后递归传入第三第四个参数。。


它的跳转到底是怎么实现的???
------解决方案--------------------
函数体内的redirect 是调用了一个函数:

参见 框架内置的functions.php文件
redirect
说明:
void redirect($url, $time=0, $msg='')
URL重定向
源码:

<br /><br />    function redirect($url, $time=0, $msg='') {<br />        //多行URL地址支持<br />        $url = str_replace(array("\n", "\r"), '', $url);<br />        if (empty($msg))<br />            $msg = "系统将在{$time}秒之后自动跳转到{$url}!";<br />        if (!headers_sent()) {<br />            // redirect<br />            if (0 === $time) {<br />                header('Location: ' . $url);<br />            } else {<br />                header("refresh:{$time};url={$url}");<br />                echo($msg);<br />            }<br />            exit();<br />        } else {<br />            $str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";<br />            if ($time != 0)<br />                $str .= $msg;<br />            exit($str);<br />        }<br />    }<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template