I have a template successfully generating the XML data but to a webpage; how do I write this to a file?
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.
Hei
As general you should be able to do something like this:
$test = $this->renderWith('template');
file_put_contents(ASSETS_PATH .'/xml.xml', $test);
Take a look here, more talk and examples how to make this work:
http://www.silverstripe.org/community/forums/dataobjectmanager-module-forum/show/16191?start=0
Above is ment if you need to write a file, if u just need output of rss/xml you can use different approach
https://docs.silverstripe.org/en/3.2/developer_guides/integration/rssfeed/
Hi
Thank you for taking the time to reply.
I'm currently using a template which triggers a few RESTful calls and generates the data in the XML template. There is nothing written to the database and so I'm having difficulties working out how to properly implement the code you cite below. i.e. onAfterWrite event handler is not triggered.
Please forgive my naïvety here as I'm still learning.
Hei
Yes this seems a bit tricky, but i wonder if u can make Director rule for xml route example something like:
Director:
rules:
'xmlpath': 'XmlController'
My idea is that u need to check when your xml is requested and then run controller to generate xml. Maybe there is some better way to do this, anyway u need to check somehow when your xml is requested ...
Hi
Both of those posts helped immensely. Thank you.
I have ended up with a successful output of formatted XML using the Director rule and procedure as per Friizu's suggestions; so that I may pass a URL to my installation and it'll output an XML based on the parameters set on that URL. Quite satisfying. Now for all the validation, security and error handling!
I did have a bunch of re-coding to do because I could not see how one could have calls to different methods from within the template if one is sending the data to the template using renderWith not without creating a separate class in the manner of a Page Controller. But this is a minor aside for the most part.
Thank you again.