Raporty w Codeigniter

Jaki jest najbardziej uproszczony sposób generowania raportów w ramach Codeigniter? Czy jest dostępna jakaś biblioteka do wykonania tego zadania? Z wyjątkiem wykresów, jakie są inne zasoby, aby to zrobić.

Author: Muhammad Raheel, 2012-06-25

3 answers

Znalazłem dobre rozwiązanie. Jeśli chcesz generować raporty w formacie csv jest to bardzo proste z codeigniter. Funkcja modelu

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()
    */
}    

Teraz w kontrolerze

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    */
}

Nie są wymagane zewnętrzne wszystko jest dostępne w codeigntier. Zdrowie! Jeśli chcesz zapisać plik xml, jest to również łatwe.
Wystarczy użyć xml_from_result() metody dbutil i użyć write_file('xml_file.xml,$new_report) Odwiedź te linki, które pomogą.

Klasa Użyteczności Bazy Danych

I

Plik Helper

 42
Author: Muhammad Raheel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-07 12:45:22

Pełne wyjaśnienie:

Model:

class Csv_m extends MY_Model {
function getCSV() {
    $sql = "SELECT * FROM tablename";
    return $this->db->query($sql);
}
}

Kontroler:

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);
}
}
 0
Author: Royal David,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-21 19:05:54

Użyłem tego do mojego .raporty csv. ma możliwość zmiany nazwy pól bazy danych w pliku csv. oto kod.

 public function export_csv() {
    $file_name = 'File_name_'.date("Y-m-d h-i-s").'.csv';
    $query = $this->db->query('SELECT 
        id as "Id", // id is table id and Id is the csv header field. 
        franchiseopt as "Nearest Location", 
        hear_about_us as "How did you hear about us?", 
        specify as "Specify",  
        email as "Email", 
        noguests as "Number of Guests", 
        eventdate as "Date of Event",
        name as "Your Name",
        phone as "Phone Number",
        locationevent as "Location of Event",
        message as "More Details"
        FROM TABLE_NAME ORDER BY id DESC');

    $this->load->dbutil();
    $data = $this->dbutil->csv_from_result($query);
    $this->load->helper('download');
    force_download($file_name, $data);  
    exit();
}

Oczywiście musisz zastąpić pola tabeli bazy danych zgodnie z tabelą.

 0
Author: Adnan Ahmad,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-16 09:14:22