Hello,
I have a template I've made to render XML, it looks like this:
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<Response>
<Sms><?php echo $message; ?></Sms>
</Response>
When I add headers to the view to declare the content type and control caching like these...
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Fri, 31 Dec 1999 11:59:00 GMT");
header("Content-type: text/xml");
... I get a "error on line 2 at column 6: XML declaration allowed only at the start of the document," which only happens when including headers; The template itself has no whitespace above the XML declaration. Any ideas on why this is and if there's a way to add HTTP headers without breaking things?
You should not use the PHP header() method in FuelPHP. It will output directly and interferes with FuelPHP's view generation system.
If you want to add headers to your output, use the set_header() method of the Reponse class to add headers to your response.
Even using set_header() or not using anything for setting headers, it seems that Fuel is adding space at the top of the rendered page even when there's no space above or before echoing the xml declaration. This space is causing it to be detected as invalid XML. Not sure how to get around that without dumping the template altogether and doing something else.