What is the most simplist way to generate reports in Codeigniter framework? Is there any library available to do this task? Except charting what are the other resources to d
Complete explanation:
Model:
class Csv_m extends MY_Model {
function getCSV() {
$sql = "SELECT * FROM tablename";
return $this->db->query($sql);
}
}
Controller:
class Generate extends CI_Controller {
var $file_path;
public function __construct() {
parent::__construct();
$this->file_path = realpath(APPPATH . '../assets/csv');
}
function index() {
$this->load->model('csv_m');
$this->load->dbutil();
$this->load->helper('file');
//get the object
$report = $this->csv_m->getCSV();
$delimiter = ",";
$newline = "\r\n";
$new_report = $this->dbutil->csv_from_result($report, $delimiter, $newline);
// write file
write_file($this->file_path . '/csv_file.csv', $new_report);
//force download from server
$this->load->helper('download');
$data = file_get_contents($this->file_path . '/csv_file.csv');
$name = 'name-'.date('d-m-Y').'.csv';
force_download($name, $data);
}
}