非法的字符串偏移量';数据';当我加载视图时


Illegal string offset 'data' when i load the view

我对这个非法的字符串偏移量有问题

这是名为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                         

问题出在模型中。它有时会返回

$query->result_array()

和其他时间返回

$query->row_array()

取决于$where值。但是result_array()给出的格式是:

$row[0]['date'];

当row_array()给出以下格式时:

$row['date'];

这就是为什么您有"非法字符串偏移量'date'"。