Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

XML content-type header


Go to End


3 Posts   8895 Views

Avatar
Vegas Rob

Community Member, 5 Posts

29 May 2010 at 10:11am

I'm creating an XML file in a SS template. The issue I'm having is that the content-type being sent is text/html.

I've tried a number of things but I'm assuming that there must be some way to from my controller class or the template file or something, to define what the content-type ought to be.

Many thanks in advance.

Avatar
Willr

Forum Moderator, 5523 Posts

29 May 2010 at 2:05pm

You can use addHeader() to add a header to the response of a particular controller action

function action() {
$this->response->addHeader("Content-Type", "application/xml");
}

And you need to make sure your xml has a valid xml header tag.

Avatar
DeklinKelly

Community Member, 197 Posts

3 February 2011 at 4:56am

It is best to put this inside init(), like this:

class XML_Controller extends Page_Controller {
   public function init(){
	$this->response->addHeader("Content-Type", "application/xml"); 
	parent::init(); 
   }
}