7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » [SOLVED] write a xml file - OnAfterWrite
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 3379 Views |
-
[SOLVED] write a xml file - OnAfterWrite

15 March 2011 at 9:32am Last edited: 15 March 2011 9:34am
It it possible to make a onAfterWrite function that writes a xml file?
I want to manage some images with the DOM .. after save and publish it must write the path of these images to a xml file.
In this way i can use the megazine3 pageflip to show my flyer online
i think it would be very very nice for silverstripe
output like this:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book SYSTEM "http://www.megazine3.de/megazine2.dtd"><book plugins="anchors, backgroundsounds, batchpages, bookmarks, console, gallery, help, javascript, keyboardnavigation, links, navigationbar, options, overlays, pdflinks, print, slideshow, swfaddress, titles">
<foreground>
</foreground>
<chapter>
<page>
<img src="http://url.nl/images/name.jpg"/>
</page>
</chapter>
</book> -
Re: [SOLVED] write a xml file - OnAfterWrite

15 March 2011 at 2:47pm
Yup. You can use onAfterWrite() or onBeforeWrite() to do just about anything. They're just open hooks.
-
Re: [SOLVED] write a xml file - OnAfterWrite

15 March 2011 at 8:57pm
How do i write this in silverstripe code?
in normal php i would do something like this:
$ourFileName = "xml.xml";
$fh = fopen($ourFileName, 'w+') or die("Can't open file");
$stringData = "<Page><img src="..."></Page>";
fwrite($fh, $stringData);
fclose($fh);Any idea?
Thx!
-
Re: [SOLVED] write a xml file - OnAfterWrite

15 March 2011 at 9:41pm
in normal php i would do something like this
That'll still work in SS, you will need to fix the path to the file. By default the file path is sapphire/ so you'll need to use "../mysite/" to get to the mysite folder. Or use can use the absolute path through BASE_PATH
-
Re: [SOLVED] write a xml file - OnAfterWrite

16 March 2011 at 5:04am
@borriej Instead of composing your XML string in PHP, I suggest you use the SilverStripe template engine.. its really nice for this kind of things as well.
Instead of BASE_PATH, you could also use ASSETS_PATH (which obviously points to the writable assets directory). Something like:protected function onAfterWrite(){
parent::onAfterWrite();// render with xml template (MyXMLTemplate.ss)
$data = $this->renderWith('MyXMLTemplate');// write data to file
file_put_contents(ASSETS_PATH .'/myXmlFile.xml', $data);
} -
Re: [SOLVED] write a xml file - OnAfterWrite

16 March 2011 at 6:56am Last edited: 16 March 2011 6:56am
wow that looks very promising. Good that I asked, I'm more of a designer.. so this comes in great
Thanks for the help everyone, will try this tonight! -
Re: [SOLVED] write a xml file - OnAfterWrite

16 March 2011 at 9:46am Last edited: 16 March 2011 9:47am
Ok.. i debugged it line by line and it seems like
$data = $this->renderWith('PageFlipXML');
is giving me problems, the file is still 0 bytes!
when changing it into $data = 'test' it will write a 4 bytes file, so it is writing.But the template cant be found i guess?
I placed my template inside mysite/templates & themes/currentTheme/templates
File name is matching offcourse.template code: PageFlipXML.ss
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book SYSTEM "http://www.megazine3.de/megazine2.dtd">
<book plugins="anchors, backgroundsounds, batchpages, bookmarks, console, gallery, help, javascript, keyboardnavigation, links, navigationbar, options, overlays, pdflinks, print, slideshow, swfaddress, titles">
<foreground>
</foreground>
<chapter><% control FlyerPaginas %>
<page>
<% control Image %><img src="$Link" /><% end_control %>
</page>
<% end_control %></chapter>
</book>
| 3379 Views | ||
| Go to Top | Next > |


