Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reports in Codeigniter

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 do this.

like image 622
Muhammad Raheel Avatar asked Jun 25 '12 12:06

Muhammad Raheel


1 Answers

Found a nice solution myself. If you want to generate reports in csv format it is very easy with codeigniter. Your model function

function index(){
return $query = $this->db->get('my_table');
    /*
    Here you should note i am returning 
    the query object instead of 
    $query->result() or $query->result_array()
    */
}    

Now in controller

function get_report(){
    $this->load->model('my_model');
    $this->load->dbutil();
    $this->load->helper('file');
    /* get the object   */
    $report = $this->my_model->index();
    /*  pass it to db utility function  */
    $new_report = $this->dbutil->csv_from_result($report);
    /*  Now use it to write file. write_file helper function will do it */
    write_file('csv_file.csv',$new_report);
    /*  Done    */
}

No externals are required everything is available in codeigntier. Cheers! If you want to write xml file it is easy too.
Just use xml_from_result() method of dbutil and use write_file('xml_file.xml,$new_report) Visit these links they will help.

Database Utility Class

And

File Helper

like image 150
Muhammad Raheel Avatar answered Nov 15 '22 21:11

Muhammad Raheel