ok, well, this works for me, not elegant, but it works. If there is a better way, please let me know.
My requirement was to have a custom form in the CMS, that allows a title, and a textarea field that will contain XML, then on the public side of the site, request the page and get an XML file, with valid headers for a content type of xml.
In my previous post I made some headway using the index function of the controller to render the view and print it out, but escaping was getting in the way.
I found that if I dispense with the view altogether, as in my case, it serves little purpose anyway, a simple echo of the field works - it does not get escaped.
FWIW..
<?php
class XMLPage extends SiteTree {
static $db = array(
'XML' => 'Text'
);
static $has_one = array(
);
static $icon = "mysite/images/treeicons/www";
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab('Root.Content.Main', 'MenuTitle');
$fields->removeFieldFromTab('Root.Content.Main', 'Content');
$fields->removeFieldFromTab('Root.Content.Metadata', 'MetaTitle');
$fields->removeFieldFromTab('Root.Content.Metadata', 'MetaDescription');
$fields->removeFieldFromTab('Root.Content.Metadata', 'MetaKeywords');
$fields->removeFieldFromTab('Root.Content.Metadata', 'ExtraMeta');
$fields->addFieldToTab('Root.Content.Main', new TextareaField(
$name = "XML",
$title = "XML Data",
$rows = 30,
$cols = 60,
$value = "<?xml version=\"1.0\"?>
<!-- Put your XML below -->
<sample>Some Data</sample>"), 'Content');
return $fields;
}
}
class XMLPage_Controller extends ContentController {
function init (){
parent::init();
}
function index() {
header("Content-Type: application/xml");
echo $this->XML;
exit;
}
}
?>