[英]Undefined variable issue in codeigniter
我正在尝试使用php从Mysql创建一个excel文件。 我找到了此链接: http : //forums.digitalpoint.com/showthread.php?t=60681并使用了他的代码。 但是,它产生了如下错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: header
Filename: controllers/export_database.php
Line Number: 26
我在控制器中的代码:
public function export ()
{
$line1="ID\tProduct\tColor\tSales\t";
$line2="1\tPrinter\tGrey\t13\t";
$line3="2\tCD\tBlue\t15\t";
$line4="3\tDVD\tRed\t7\t";
$line5="4\tMonitor\tGreen\t4\t";
$line6="5\tTelephone\tBlack\t2\t";
$data="$line1\n$line2\n$line3\n$line4\n$line5\n$line6\n";
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data"; //line 26
}
}
我不确定为什么标头是未定义的变量。 有什么想法吗? 感谢帮助。
header()
函数将这些数据推送给您的浏览器。 它不会创建$ header变量,因此会出错。
删除$header
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.