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.

General Questions /

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

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

XML content-type header


Reply


3 Posts   4706 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, 5513 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();
}
}