YRedirect.class.php 987 Bytes
<?php
/**
 * 封装页面跳转方法
 * 
 * @version 0.1 2012-6-25
 * @name Framework_Response_YForward
 * @author xiaoma 
 */
class Framework_Response_YRedirect 
{
	/**
	 * 重定向 URL
	 *
	 * @var string
	 */
	protected $url;
	
	/**
	 * 重定向延时(秒)
	 *
	 * @var int
	 */
	protected $delay;
	
	/**
	 * 脚本(当delay>0时有效)
	 *
	 * @var string
	 */
	protected $scripts;
	
	/**
	 * 构造函数
	 *
	 * @param string $url
	 * @param int $delay
	 */
	public function __construct($url, $delay = 0, $scripts = '') 
	{
		$this->url = $url;
		$this->delay = $delay;
		$this->scripts = $scripts;
	}
	
	/**
	 * 执行
	 */
	function execute() 
	{
		$url = $this->url;
		$delay = (int) $this->delay;
		if ($delay > 0) 
		{
			$scripts = $this->scripts;
			return  <<<EOT
<html>
	<head>
		<meta http-equiv="refresh" content="$delay;URL=$url" />
		<script type="text/javascript>$scripts</script>
	</head>
</html>
EOT;
		} 
		else 
		{
			header('Location: ' . $url);
		}
	}
}