From dfdef9a4439be22078226105345128f2117ee5d1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 18 Jul 2017 16:18:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bxmlresponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/response/Xml.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/think/response/Xml.php b/library/think/response/Xml.php index ca12e295..87479be9 100644 --- a/library/think/response/Xml.php +++ b/library/think/response/Xml.php @@ -11,6 +11,8 @@ namespace think\response; +use think\Collection; +use think\Model; use think\Response; class Xml extends Response @@ -81,6 +83,11 @@ class Xml extends Response protected function dataToXml($data, $item, $id) { $xml = $attr = ''; + + if ($data instanceof Collection || $data instanceof Model) { + $data = $data->toArray(); + } + foreach ($data as $key => $val) { if (is_numeric($key)) { $id && $attr = " {$id}=\"{$key}\"";