Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

exporting page data as csv


Go to End


4 Posts   2424 Views

Avatar
macka

Community Member, 33 Posts

13 November 2014 at 2:52pm

Hi,

I've got some data on a page i'd like to create a button so the user can save as a CSV file.

Does anyone have any pointers how i might go about that?

Thanks
Grant

Avatar
swaiba

Forum Moderator, 1899 Posts

14 November 2014 at 8:10am

If you add your DataObjects for your pages and any associated DataObjects to a ModelAdmin then a button is automatically scaffolded to export to csv based on the summary fields (but is easily overridden to return a different set of fields).

If that isn't how you'd like to present it you can always just use the same code to create the button elsewhere

Avatar
macka

Community Member, 33 Posts

17 November 2014 at 9:38am

Hi swaiba,

Is that more in the CMS, as i want it on the page the user is on in the front end.

Thanks
Grant

Avatar
codemonkey88

Community Member, 24 Posts

12 December 2014 at 6:28am

Edited: 12/12/2014 6:27am

Don't know if you've cracked this one yet. If not, if you do

$data = DataObjectSet::toNestedArray();
I would have thought you can use fputcsv http://php.net/manual/en/function.fputcsv.php