From df96d049b9dc1a3af15a519941fe38b9c8ddbe73 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 17 May 2016 10:23:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Request=E7=B1=BB=E7=9A=84only?= =?UTF-8?q?=E5=92=8Cexcept=E6=96=B9=E6=B3=95=20=E6=94=AF=E6=8C=81=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E4=BC=A0=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/library/think/Request.php b/library/think/Request.php index 29c42e25..4be21392 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -406,14 +406,17 @@ class Request */ public function only($name) { + $param = $this->param(); if (is_string($name)) { - return $this->param($name); - } else { - foreach ($name as $key) { - $item[$key] = $this->param($name); - } - return $item; + $name = explode(',', $name); } + $item = []; + foreach ($name as $key) { + if (isset($param[$key])) { + $item[$key] = $param[$key]; + } + } + return $item; } /** @@ -426,14 +429,11 @@ class Request { $param = $this->param(); if (is_string($name)) { - if (isset($param[$name])) { - unset($param[$name]); - } - } else { - foreach ($name as $key) { - if (isset($param[$key])) { - unset($param[$key]); - } + $name = explode(',', $name); + } + foreach ($name as $key) { + if (isset($param[$key])) { + unset($param[$key]); } } return $param;