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.

Customising the CMS /

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

Export file CSV in page CMS, not using ModelAdmin


Go to End


1132 Views

Avatar
nhi_phan

Community Member, 1 Post

27 December 2014 at 3:21pm

Hello all,
I am new in Silverstripe. I am doing with exporting content to file CSV from pages in backend.
I create a button to export. However, when I export it just redirect to content, not OPEN DOWNLOAD FILE WINDOW.
"Code here:
$fileName = "export";
$testfilePath = "assets/$fileName.csv"; // Important: No leading slash
//$filter= 'ID='.$data['ID'];
$pageFromDB = SiteTree::get()->byId($data['ID']);
$filter="OwnerID='3'";
$service = DataObject::get('Service', $filter,"","","");
$arr = array();
$fh = fopen(BASE_PATH . '/' . $testfilePath, "w");
$new_page=array(
$data['Title'],
$data['URLSegment'],
$data['MenuTitle'],
$data['Content'],
$data['ClassName'],
$data['Action']
);
$data_object=array((array)$new_page,$arr);
$my_json = json_encode($data_object);
fwrite($fh,$my_json, strlen($my_json));
fclose($fh);
$this->owner->redirect(Director::protocolAndHost().''.Director::baseURL().''. $testfilePath);
return $this->owner->getResponseNegotiator()
->respond($this->owner->request);
"

Please give me a solution to open new window to download instead refresh to show it for download.
Thank you!