如果您想直接输出文件,则需要设置 XML 标头:
使用代码点火器输出等级 http://codeigniter.com/user_guide/libraries/output.html:
$xml = $this->dbutil->xml_from_result($query, $config);
$this->output->set_content_type('text/xml');
$this->output->set_output($xml);
或者您可以使用纯 PHP 来设置headers http://php.net/manual/en/function.header.php:
header('Content-type: text/xml');
echo $this->dbutil->xml_from_result($query, $config);
或者你可以使用 CI下载助手 http://codeigniter.com/user_guide/helpers/download_helper.html:
$xml = $this->dbutil->xml_from_result($query, $config);
$this->load->helper('download');
force_download('myfile.xml', $xml);
或者使用以下命令将其写入文件文件助手 http://codeigniter.com/user_guide/helpers/file_helper.html:
$xml = $this->dbutil->xml_from_result($query, $config);
$this->load->helper('file');
$file_name = '/path/to/myfile.xml';
write_file($file_name, $xml);
// Optionally redirect to the file you (hopefully) just created
redirect($file_name);