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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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   7840 Views

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.


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.


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");