This is exactly what I’m needing, but I’m running into an issue.
I am using xdbedit to create a CMP for managing custom table data. I have everything working just fine except the export functionality. What I’d like is to add an export button to the actions section. When clicking on that button the export should be forced to download.
Here is my export.php processor:
<?php
$config=$modx->xdbedit->customconfigs;
$prefix = $config['prefix'];
$packageName = $config['packageName'];
$tablename = $config['tablename'];
$packagepath = $modx->getOption('core_path') . 'components/'.$packageName.'/';
$modelpath = $packagepath.'model/';
$modx->addPackage($packageName,$modelpath,$prefix);
$classname = $modx->xdbedit->getClassName($tablename);
if ($this->modx->lexicon)
{
$this->modx->lexicon->load($packageName.':default');
}
/* setup default properties */
$isLimit = !empty($scriptProperties['limit']);
$isCombo = !empty($scriptProperties['combo']);
$start = $modx->getOption('start',$scriptProperties,0);
$limit = $modx->getOption('limit',$scriptProperties,20);
$sort = $modx->getOption('sort',$scriptProperties,'id_req');
$dir = $modx->getOption('dir',$scriptProperties,'ASC');
$year = $modx->getOption('year',$scriptProperties,'all');
$month = $modx->getOption('month',$scriptProperties,'all');
$showtrash = $modx->getOption('showtrash',$scriptProperties,'');
$c = $modx->newQuery($classname);
$count = $modx->getCount($classname,$c);
$c->select('
`'.$classname.'`.*
');
$collection = $modx->getCollection($classname, $c);
foreach($collection as $item) {
$output .= implode(',', str_replace("\r\n","",$item->toArray())) . PHP_EOL;
}
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename=excelreport.csv');
header("Content-Type: application/force-download");
header("Cache-Control: post-check=0, pre-check=0", false);
return $output;
In my button group I have added (this successfully adds the button):
},{
text: _(Xdbedit.customconfigs.task + '.export') || _('xdbedit.export')
,handler: this.export_items
,enableToggle: false
,scope: this
and for my export_items function is have:
,export_items: function() {
MODx.Ajax.request({
url: this.config.url
,params: {
action: 'mgr/'+Xdbedit.customconfigs.task+'/export'
,task: 'export'
,configs: this.config.configs
}
});
}
The error I’m getting is "missing ) in parenthetical".
In Firebug, the console’s POST response shows all of the data correctly.
However, the net response for connector.php doesn’t show anything.
Can you help?? The client is coming in tomorrow morning for a MODx training and this is the last item to build out. Thanks!!