2012-06-25 6 views
14

में रिपोर्ट कोडिनेटर ढांचे में रिपोर्ट जेनरेट करने का सबसे आसान तरीका क्या है? क्या इस कार्य को करने के लिए कोई लाइब्रेरी उपलब्ध है? चार्टिंग को छोड़कर ऐसा करने के लिए अन्य संसाधन क्या हैं।कोडिनेटर

+0

मेरे अनुभव में मुझे कुछ भी नहीं मिला। क्या मुझे पता है कि आप किस प्रकार की रिपोर्ट देख रहे हैं? – LoganPHP

+0

मैं एक क्वेरी से रिपोर्ट जेनरेट करना चाहता हूं। किसी भी प्रारूप सीएसवी, पीडीएफ या अन्य –

उत्तर

41

मुझे एक अच्छा समाधान मिला। यदि आप सीएसवी प्रारूप में रिपोर्ट जेनरेट करना चाहते हैं तो यह कोडनिर्देशक के साथ बहुत आसान है। आपका मॉडल समारोह

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

नियंत्रक

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

में कोई बाहरी आवश्यक हैं सब कुछ codeigntier में उपलब्ध है। चीयर्स! यदि आप xml फ़ाइल लिखना चाहते हैं तो यह भी आसान है।
बस xml_from_result() dbutil विधि का उपयोग करें और write_file('xml_file.xml,$new_report) का उपयोग करें इन लिंक पर जाएं जो वे मदद करेंगे।

Database Utility Class

और

File Helper

+0

होना चाहिए यह एक्सेल फ़ाइल सर के लिए काम कर रहा है? – wewe

+0

@wewe मैंने कभी एक्सेल फ़ाइल के लिए इसका परीक्षण नहीं किया है, लेकिन आप डेटाबेस क्षेत्र नाम को रद्द करने के लिए –

+0

का परीक्षण और उल्लेख कर सकते हैं? केवल रिकॉर्ड शो? सीएसवी – wewe

0

पूरा विवरण:

मॉडल:

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

नियंत्रक:

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

मैंने इसे अपने .csv रिपोर्ट के लिए उपयोग किया। इसमें सीएसवी फ़ाइल में डेटाबेस फ़ील्ड नाम बदलने की क्षमता है। यहां कोड है।

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(); 
} 

स्पष्ट रूप से आपको अपनी तालिका के अनुसार डेटाबेस तालिका फ़ील्ड को प्रतिस्थापित करने की आवश्यकता है।