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!