From c00a255660f7aac85cfa0536da0febfc90765f35 Mon Sep 17 00:00:00 2001 From: Alan Date: Thu, 29 Feb 2024 13:00:41 +0800 Subject: [PATCH] JsonOutputTrait.php --- JsonOutputTrait.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/JsonOutputTrait.php b/JsonOutputTrait.php index 3d7e2403..a035934e 100644 --- a/JsonOutputTrait.php +++ b/JsonOutputTrait.php @@ -175,6 +175,14 @@ trait Pman_Core_JsonOutputTrait { + + /** + * output data for grids or tree + * @ar {Array} ar Array of data + * @total {Number|false} total number of records (or false to return count(ar) + * @extra {Array} extra key value list of data to pass as extra data. + * + */ function jdata($ar,$total=false, $extra=array(), $cachekey = false) { // should do mobile checking??? @@ -182,8 +190,7 @@ trait Pman_Core_JsonOutputTrait { $total = count($ar); } $extra= $extra ? $extra : array(); - require_once 'Services/JSON.php'; - $json = new Services_JSON(); + $retHTML = isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']); @@ -199,11 +206,11 @@ trait Pman_Core_JsonOutputTrait { if ($retHTML) { header('Content-type: text/html'); - echo ""; + echo "'), array('\u003c','\u003e'), - $json->encodeUnsafe(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra)); - echo ""; + $this->jsencode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra, false)); + echo "]]>"; exit; } @@ -227,7 +234,7 @@ trait Pman_Core_JsonOutputTrait { } - $ret = $json->encode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra); + $ret = $this->jsencode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra,true); if (!empty($cachekey)) { @@ -237,10 +244,13 @@ trait Pman_Core_JsonOutputTrait { } file_put_contents($fn, $ret); } + echo $ret; exit; } + + /** a daily cache **/ function jdataCache($cachekey) { @@ -253,4 +263,5 @@ trait Pman_Core_JsonOutputTrait { return false; } + } \ No newline at end of file -- 2.39.2