October 12, 2015, 7:50pm
Hi all, I am looking for the best practice way for Neos 2 to create and update files at the back end using Flow3 Resources. Can anyone point me in the right direction? I’ve had a look at the documentation (
http://flowframework.readthedocs.org/en/stable/TheDefinitiveGuide/PartIII/ResourceManagement.html ) but looking for examples.
What I would like to do is create a CSV file as a back up for an enquiry form.
November 4, 2015, 10:48am
Hi Nick, sorry for the late reply …
What you basically need to do is using the
ResourceManager to import a new
Resource object from a file or content.
So, let’s assume you have a file somewhere which contains the CSV data, then you inject the
ResourceManager as a property of your class (probably a controller) and then do:
$resource = $this->resourceManager->importResource('/tmp/yourfile.csv'');
Now you have a (persisted) Resource object, but you probably want to attach it to some other object (a domain model) in order to find it again, for example a
$backup = new Backup;
If you don’t have a CSV file but generated the data in memory, you can simply import the resource from content:
$resource = $this->resourceManager->importResourceFromnContent($myCsvData);
Does that help?
November 26, 2015, 2:41pm
thanks for getting back to me on this. I moved on, hence my late reply, and decided to use a model object to persist the data and update the data for now in the db. But I will come back to this and see if I can get it to work.
From what you have said I think I understand that if I connect the persistent resource to a model object I can reload it update it and save it again?
November 26, 2015, 2:47pm
yes, more specifically, what you would do is
upload a new file, which results in a brand new resource object
detach the old resource object from the model
attach (add) the new resource object to the model
make sure to persist the updated
mode by calling update() on its repository
Flow will clean up all unused resource data and make sure to unpublish resources (even from a CDN) when they are not referenced by any resource object any more.