Muh*_*eel 14 php csv codeigniter report codeigniter-2
在Codeigniter框架中生成报告的最简单方法是什么?有没有可用于执行此任务的库?除了绘制其他资源以外做什么.
Muh*_*eel 42
我自己找到了一个很好的解 如果要生成csv格式的报告,使用codeigniter非常容易.你的模特功能
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()
*/
}
Run Code Online (Sandbox Code Playgroud)
现在在控制器中
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 */
}
Run Code Online (Sandbox Code Playgroud)
不需要外部代码.在codeigntier中可以使用所有内容.干杯! 如果你想写xml文件也很容易.
只需使用xml_from_result()
dbutil的方法并使用write_file('xml_file.xml,$new_report)
访问这些链接,他们将提供帮助.
和