After migrating to CI 3.0 from 2.0 I'm having a problem with xml output. I do that through restserver with this code on the controller:
从2.0迁移到CI 3.0后,我遇到了xml输出问题。我通过restserver在控制器上使用此代码执行此操作:
$xml = $this->_toRss($q);
$this->response->format = 'xml';
$this->response($xml, 200 );
$xml is an SimpleXMLElement which I create and assemble with code like this:
$ xml是一个SimpleXMLElement,我使用这样的代码创建和汇编:
$xmlRoot = new SimpleXMLElement("<rss/>");
$xml = $xmlRoot;
$xml->addAttribute("version", "1.0");
$channel = $xml->addChild("channel");
$channel->addChild("title", "My Company");
$channel->addChild("link", xml_convert($curURL));
$channel->addChild("description", "RSS feed");
The code did not change on this migration.
该迁移的代码没有改变。
Here is an example of the response working on 2.0: http://pastebin.com/JfNNJeH7
以下是2.0的响应示例:http://pastebin.com/JfNNJeH7
And here is an example of the response on 3.0: http://pastebin.com/ubDCNnhD
以下是3.0上的响应示例:http://pastebin.com/ubDCNnhD
1 个解决方案
#1
0
This will be registered as a bug on restserver but here is a workaround for whoever needs it:
这将在restserver上注册为一个bug,但这里有一个解决方法,无论谁需要它:
$this->output->set_status_header(200);
$this->output->set_content_type('application/xml', strtolower($this->config->item('charset')));
$this->output->set_output($xml->asXML());
#1
0
This will be registered as a bug on restserver but here is a workaround for whoever needs it:
这将在restserver上注册为一个bug,但这里有一个解决方法,无论谁需要它:
$this->output->set_status_header(200);
$this->output->set_content_type('application/xml', strtolower($this->config->item('charset')));
$this->output->set_output($xml->asXML());