Jump to:

23371 Posts in 18161 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » XML content-type header

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

Page: 1
Go to End
Author Topic: 4243 Views
  • Vegas Rob
    Avatar
    Community Member
    5 Posts

    XML content-type header Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: XML content-type header Link to this post

    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.

  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    Re: XML content-type header Link to this post

    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();
    }
    }

    4243 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.