public function export($results){ $file_name = 'fusion_search_on_'.date('Ymd').'.csv'; header("Content-Description: File Transfer"); header("Content-Type: application/csv;"); header("Content-Disposition: attachment; filename=$file_name"); // file creation $file = fopen('php://output', 'w'); $header = ['Incoming Date','WWNDT Job #', 'Operator', 'Division', 'Job Number', 'Fusers Name', 'Size']; fputcsv($file, $header); //echo implode("\t", $header) . "\r\n"; foreach ($results as $key => $fusion) { $row = []; $row[] = date( 'm/d/Y',strtotime($fusion->incoming_date)); $row[] = $fusion->wwndt; $operator = $this->GeneralModel->findByField('id',$fusion->operator_id,'users'); $row[] = ($operator)?$operator->name:'N/A'; $division = $this->GeneralModel->findByField('id',$fusion->division_id,'divisions'); $row[] = ($division)?$division->name:'N/A'; $row[] = $fusion->job_no; $fuser = $this->GeneralModel->findByField('id',$fusion->fuser_id,'users'); $row[] = ($fuser)?$fuser->name:'N/A'; $pipeSizeRow = $this->GeneralModel->findByField('id',$fusion->size,'pipe_sizes'); $pipeSize = ($pipeSizeRow)?$pipeSizeRow->size:'N/A'; $row[] = $this->GeneralModel->formatPipeSize($pipeSize).'"'; fputcsv($file, $row); } fclose($file); }