From f37b93a7eb34c766d2d741064a611afd1760c959 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 14 Feb 2010 07:31:11 -0800 Subject: If the return object is empty still return the empty object in the json response. --- modules/rest/helpers/rest.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'modules/rest/helpers/rest.php') diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php index a61aba2f..3c53784d 100644 --- a/modules/rest/helpers/rest.php +++ b/modules/rest/helpers/rest.php @@ -21,17 +21,15 @@ class rest_Core { static function reply($data=array()) { Session::instance()->abort_save(); - if ($data) { - if (Input::instance()->get("output") == "html") { - header("Content-type: text/html"); - $html = preg_replace( - "#([\w]+?://[\w]+[^ \'\"\n\r\t<]*)#ise", "'\\1'", - var_export($data, 1)); - print "
$html
"; - } else { - header("Content-type: application/json"); - print json_encode($data); - } + if (Input::instance()->get("output") == "html") { + header("Content-type: text/html"); + $html = preg_replace( + "#([\w]+?://[\w]+[^ \'\"\n\r\t<]*)#ise", "'\\1'", + var_export(!empty($data) ? $data : t("Empty response"), 1)); + print "
$html
"; + } else { + header("Content-type: application/json"); + print json_encode($data); } } -- cgit v1.2.3 From 1377b2c7b3110a132d4b2d748be72a6aafa537e6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 20 Feb 2010 10:24:29 -0800 Subject: When using rest::reply(), don't call var_export() if the response is empty. --- modules/rest/helpers/rest.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'modules/rest/helpers/rest.php') diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php index 3c53784d..1ee72aed 100644 --- a/modules/rest/helpers/rest.php +++ b/modules/rest/helpers/rest.php @@ -23,9 +23,13 @@ class rest_Core { if (Input::instance()->get("output") == "html") { header("Content-type: text/html"); - $html = preg_replace( - "#([\w]+?://[\w]+[^ \'\"\n\r\t<]*)#ise", "'\\1'", - var_export(!empty($data) ? $data : t("Empty response"), 1)); + if ($data) { + $html = preg_replace( + "#([\w]+?://[\w]+[^ \'\"\n\r\t<]*)#ise", "'\\1'", + var_export($data, 1)); + } else { + $html = t("Empty response"); + } print "
$html
"; } else { header("Content-type: application/json"); -- cgit v1.2.3