Jump to content


This topic is now archived and is closed to further replies.


export to csv

Recommended Posts


class ReportsController extends AppController {

    public function asset_cat_aov() {
        $this->set('title_for_layout', __('Asset Category Average Order Value', true));
        $this->set('data', $this->Report->query("SELECT * FROM report_asset_cat_aov AS Report;"));
    public function asset_aov() {
        $this->set('title_for_layout', __('Asset Average Order Value', true));
        $this->set('data', $this->Report->query("SELECT * FROM report_asset_aov AS Report;"));
    public function accrual_export()
        ini_set('max_execution_time', 600);
        Configure::write('debug', 0);
        if($this->request->is('post')) {
            $filename = "export_".date("Y.m.d").".csv";
            $results = $this->Report->query("
                FROM report_accrual AS Report;
            $csv_file = fopen('php://output', 'w');
            header('Content-type: application/csv');
            header('Content-Disposition: attachment; filename="'.$filename.'"');
            $headers = array(
                'Job Ref',
                'Site Ref',
                'Postal Code',
                'Area Name',
                'Asset Category',
            // Each iteration of this while loop will be a row in your .csv file where each field corresponds to the heading of the column
            foreach($results as $result)
                $row = array(
        $this->layout = false;
        return false;




this link gives me a blank page, I am expecting it to give me a file download???

Share this post

Link to post
Share on other sites



Went with this in the end.


$this->set('account_status', $this->Report->query("SELECT * FROM report_account_status AS Report;"));
$this->layout = 'csv/default';



Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.