我试图创建一个按钮,以强制下载CSV文件,但由于某些原因,我无法使其正常工作。这是我的代码:
public function export_to_csv($result) {
$shtml="";
for ($i=0; $i<count($result); $i++){
$shtml = $shtml.$result[$i]["order_number"]. "," .$result[$i]["first_name"]. "," .$result[$i]["middle_name"]. "," .$result[$i]["last_name"]. "," .$result[$i]["email"]. "," .$result[$i]["shipment_name"]. "," .$result[$i]["payment_name"]. "," .$result[$i]["created_on"]. "," .$result[$i]["modified_on"]. "," .$result[$i]["order_status"]. "," .$result[$i]["order_total"]. "," .$result[$i]["virtuemart_order_id"]. "\n";
}
Header('Content-Description: File Transfer');
Header('Content-Type: application/force-download');
Header('Content-Disposition: attachment; filename=pedidos.csv');
}
$result变量来源于此处:
public function get_orders_k() {
$db=JFactory::getDBO();
$query = " select o.order_number, o.virtuemart_order_id, o.order_total, o.order_status, o.created_on, o.modified_on, u.first_name,u.middle_name,u.last_name "
.',u.email, pm.payment_name, vsxlang.shipment_name ' .
$from = $this->getOrdersListQuery();
$db->setQuery($query);
$result=$db->loadAssocList();
if ( $result > 0 )
{
$datos = VirtueMartModelKiala::export_to_csv($result);
}else return 0;
}
我甚至不确定从哪里开始寻找。我在互联网上查看了各种方法,并尝试了所有这些方法,但仍然无法使其正常工作。请帮助我!
- 谢谢