This commit is contained in:
thinkphp
2016-05-17 14:05:58 +08:00
3 changed files with 23 additions and 4 deletions

View File

@@ -426,7 +426,7 @@ function xml($data = [], $code = 200, $options = [])
* @param array $params 额外参数
* @return \think\response\Redirect
*/
function redirect($url = [], $code = 200, $params = [])
function redirect($url = [], $code = 302, $params = [])
{
return Response::create($url, 'redirect')->code($code)->params($params);
}

View File

@@ -206,7 +206,6 @@ class Session
* @param string $name session名称
* @param string|null $prefix
* @return bool
* @internal param mixed $value session值
*/
public static function has($name, $prefix = null)
{

View File

@@ -11,7 +11,9 @@
namespace think\response;
use think\Request;
use think\Response;
use think\Session;
use think\Url;
class Redirect extends Response
@@ -30,10 +32,9 @@ class Redirect extends Response
*/
protected function output($data)
{
$this->isExit = true;
$url = preg_match('/^(https?:|\/)/', $data) ? $data : Url::build($data, $this->params);
$this->header['Location'] = $url;
$this->header['status'] = isset($this->header['status']) ? $this->header['status'] : 301;
$this->header['status'] = isset($this->header['status']) ? $this->header['status'] : 302;
$this->header['Cache-control'] = 'no-cache,must-revalidate';
return;
}
@@ -43,4 +44,23 @@ class Redirect extends Response
$this->params = $params;
return $this;
}
/**
* 记住当前url后跳转
*/
public function remember()
{
Session::set('redirect_url', Request::instance()->url());
}
/**
* 跳转到上次记住的url
*/
public function restore()
{
if (Session::has('redirect_url')) {
$this->data = Session::get('redirect_url');
Session::delete('redirect_url');
}
}
}