我对这个非法字符串偏移有疑问
这是名为 formlembur.php 的控制器
function download($lid)
{
$form_lembur = $this->form_lembur->read(array('lid' => $lid));
$data['form_lembur'] = $form_lembur;
//echo $data;die;(until this statement,it can load the data on database.
//it actually showing the data.
$this->load->view('exp-lembur', $data);
}
这是名为 form_lembur.php 的模型
public function read($where = FALSE)
{
if ($where === FALSE)
{
$query = $this->db->get('form_lembur');
return $query->result_array();
}
$query = $this->db->get_where('form_lembur', $where);
return $query->row_array();
}
这是我下载之前的视图
<td> <a href="<?php echo base_url();?>formlembur/download/<?php echo $data->lid; ?>"><input type="submit" name="download" value="Download"></a></td>
这是我希望在名为 exp-lembur.php 的 excel 上查看数据的视图
<?php
header("Content-type: application/vnd.openxmlformats xlsx");
header("Content-disposition: attachment; filename=\"Lembur.xls\"");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=ProgId content=Excel.Sheet>
<title>Reports</title>
<style>
table.member
{
border:.5pt solid #000;
border-collapse:collapse;
font:14px tahoma;
margin:0 auto;
width:50%
}
table.member tr th{background-color:#999;border:.5pt solid #000}
table.member tr.head th{color:#fff}
table.member tr.data td{border:.5pt solid #000; vertical-align: top}
</style>
</head>
<body>
<?php
//print 'Generated On ' .date("j M y, g:i a",time()). '<br>';
?>
<table class="member">
<thead>
<tr class="head">
<th>Tanggal</th>
<th>Nama</th>
<th>Jabatan</th>
<th>Jam Pulang</th>
<th>Keperluan</th>
<th>Instruktur</th>
<th>Status</th>
<th>Uang Lembur</th>
</tr>
</thead>
<tbody>
<?php
if (isset($form_lembur)){
foreach($form_lembur as $k){
print <<<h
<tr class="data">
<td>{$k['date']}</td>
<td>{$k['nama']}</td>
<td>{$k['jabatan']}</td>
<td>{$k['jampulang']}</td>
<td>{$k['keperluan']}</td>
<td>{$k['instruktur']}</td>
<td>{$k['status']}</td>
<td>{$k['uanglembur']}</td>
</tr>
h;
}
}
?>
</tbody>
</table>
</body>
</html>
但问题是,它说它是一个非法的字符串偏移量。问题是什么 ?请帮我。
这是错误消息(显示在 excel 文档上,因为我尝试将其下载到 excel 文档中)
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'date'
Filename: views/exp-lembur.php
Line Number: 50