From 704337eb20036659899865b5581ef3dab871d5a5 Mon Sep 17 00:00:00 2001 From: augushong Date: Sun, 6 Dec 2020 22:20:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96baseController,=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=B7=B3=E8=BD=AC=E6=96=B9=E6=B3=95=20;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/BaseController.php | 51 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/app/BaseController.php b/app/BaseController.php index 638a9e5..72e1aeb 100644 --- a/app/BaseController.php +++ b/app/BaseController.php @@ -106,20 +106,7 @@ abstract class BaseController public function success($msg = '操作成功', $jump_to_url = null, $code = 200, $params = []) { - - if (is_null($jump_to_url)) { - $jump_to_url = \request()->server('HTTP_REFERER'); - } else { - if ($jump_to_url instanceof Url) { - - $jump_to_url = (string)$jump_to_url; - } else { - if (strpos($jump_to_url, 'http') !== 0) { - $jump_to_url = url($jump_to_url); - } - } - } - + $jump_to_url = $this->parseJumpUrl($jump_to_url); $data = [ 'msg' => $msg, 'jump_to_url' => $jump_to_url, @@ -140,18 +127,7 @@ abstract class BaseController public function error($msg = '操作失败', $jump_to_url = null, $code = 200, $params = []) { - if (is_null($jump_to_url)) { - $jump_to_url = \request()->server('HTTP_REFERER'); - } else { - if ($jump_to_url instanceof Url) { - - $jump_to_url = (string)$jump_to_url; - } else { - if (strpos($jump_to_url, 'http') !== 0) { - $jump_to_url = url($jump_to_url); - } - } - } + $jump_to_url = $this->parseJumpUrl($jump_to_url); $data = [ 'msg' => $msg, @@ -170,4 +146,27 @@ abstract class BaseController View::assign($data); throw new HttpResponseException(response(View::fetch('common@tpl/error'), $code)); } + + public function redirect($jump_to_url, $code = 302) + { + $jump_to_url = $this->parseJumpUrl($jump_to_url); + + throw new HttpResponseException(redirect($jump_to_url), $code); + } + + public function parseJumpUrl($jump_to_url) + { + if (is_null($jump_to_url)) { + $jump_to_url = \request()->server('HTTP_REFERER'); + } else { + if ($jump_to_url instanceof Url) { + + $jump_to_url = $jump_to_url; + } else { + $jump_to_url = url($jump_to_url); + } + } + + return (string)$jump_to_url; + } }