我有一个创建xml节点的函数,如下所示:
req.collections.dayTrainings.count(
{
'phone': req.param('phone'),
'day': { $lte: theday }
},
function (error, trainingCount) {
}
)
我得到xml节点的输出,如下所示:
$xml_data = array(
"test" => $this->get_info_for_XML($profile->id),
);
$this->array2xml->writeSettingsFile($xml_data);
public function get_info_for_XML($id)
{
$output = [];
$results = $this->db->select('id, settings')->where('id', $id)->get('profile')->result();
foreach ($results as &$result) {
$setting = unserialize($result->settings);
$output[] = [
'StartDate' => $setting['start_date'],
'EndDate' => $setting['end_date'],
];
}
return ['Periods' => $output];
}
但是我希望输出如下:
<test>
<Periods>
<StartDate>2018-06-20</StartDate>
<StartDate>2018-06-22</StartDate>
<EndDate>2019-06-20</EndDate>
<EndDate>2019-06-22</EndDate>
</Periods>
</test>
任何帮助将不胜感激。在数据库中,设置字段是开始日期和结束日期的序列化数组。