mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
增加记忆跳转
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user