From 5377eef475395fbc22cbe56ae2788bfdd386470d Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 20 Jul 2021 11:30:09 +0800 Subject: [PATCH] * adjust for api. --- framework/api/entry.class.php | 8 ++++---- framework/api/router.class.php | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/framework/api/entry.class.php b/framework/api/entry.class.php index 07e5c37881..f742ccb185 100644 --- a/framework/api/entry.class.php +++ b/framework/api/entry.class.php @@ -18,7 +18,7 @@ class entry extends baseEntry * The baseEntry class file of ZenTao API. * */ -class baseEntry +class baseEntry { /** * 全局对象 $app。 @@ -164,7 +164,7 @@ class baseEntry { header("Content-type: application/json"); header("HTTP/1.1 {$this->statusCode[$code]}"); - echo json_encode($data); + echo json_encode($data); exit; } @@ -341,8 +341,8 @@ class baseEntry $fields = explode(',', $fields); foreach($fields as $field) { - /* - * If the field exists in request body, use it. + /* + * If the field exists in request body, use it. * Otherwise set default value from $object. */ if(isset($this->requestBody->$field)) diff --git a/framework/api/router.class.php b/framework/api/router.class.php index 9c6f96d773..afa53277b7 100644 --- a/framework/api/router.class.php +++ b/framework/api/router.class.php @@ -88,7 +88,7 @@ class api extends router } else { - $this->path = rtrim((strpos($_SERVER['REQUEST_URI'], '?') > 0 ? strstr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI']), '/'); + $this->path = trim((strpos($_SERVER['REQUEST_URI'], '?') > 0 ? strstr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI']), '/'); } $dir = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'); @@ -96,8 +96,8 @@ class api extends router $subPos = strpos($this->path, '/', 1); - $this->version = substr($this->path, 1, $subPos-1); - $this->path = substr($this->path, $subPos); + $this->version = $subPos ? substr($this->path, 1, $subPos - 1) : ''; + $this->path = $subPos ? substr($this->path, $subPos) : $this->path; } /** @@ -128,15 +128,15 @@ class api extends router $this->action = strtolower($_SERVER['REQUEST_METHOD']); /* Set params */ - foreach($this->paramNames as $name) + foreach($this->paramNames as $name) { if(!isset($paramValues[$name])) continue; - if(isset($this->paramNamesPath[$name])) + if(isset($this->paramNamesPath[$name])) { $this->params[$name] = explode('/', urldecode($paramValues[$name])); - } - else + } + else { $this->params[$name] = urldecode($paramValues[$name]); } @@ -220,6 +220,7 @@ class api extends router $data->status = isset($output->status) ? $output->status : $output->result; if(isset($output->message)) $data->message = $output->message; if(isset($output->data)) $data->data = json_decode($output->data); + if(isset($output->id)) $data->id = $output->id; $output = json_encode($data); unset($_SESSION['ENTRY_CODE']);