改进xmlresponse

This commit is contained in:
thinkphp
2017-07-18 16:18:45 +08:00
parent 14de36b6f4
commit dfdef9a443

View File

@@ -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}\"";