数组数据未从控制器传递到视图

时间:2017-01-25 09:48:45

标签: arrays codeigniter

我在codeigniter中编写代码试图将我的用户数据从控制器传递到视图,但数据没有传递并弹出错误消息,请帮我解决这个问题。

控制器

public function customerRecive($cust_ID)
     {
          $ID_decript = base64_decode($cust_ID);
          $this->db->where('CustomerID', $ID_decript);
          $query=$this->db->get('gst_customermaster');
          $cust_details= $query->result_array();
          $data['cust_details'] = $cust_details;
          //print_r($cust_details);
          //load the department_view
          $this->load->view('category_link_details_view',$data);

     }

查看

<table class='table table-bordered'>
                <thead>
                  <tr>
                  <th> # </th>
                  <th> CustomerCode</th>
                  <th> CustomerName</th>
                  <th> ContactPerson</th>
                  <!--<th> Edit</th>-->
                  <th> Delete</th>
                </thead>
                  <tbody>
                      <?php for ($i = 0; $i < count($cust_details); ++$i) { ?>
                                <tr>
                                     <td><?php echo ($i+1); ?></td>
                                     <td><?php echo $cust_details[$i]->CustomerCode; ?></td>
                                     <td><?php echo $cust_details[$i]->CustomerName; ?></td>
                                     <td><?php echo $cust_details[$i]->ContactPerson; ?></td>
                                     <!-- <td><a href="#" onClick="show_confirm('edit',<?php $cust_details[$i]->id;?>)">Edit</a></td> -->

                                     <!-- <td><a href="<?php echo base_url();?>index.php/<?php $cust_details[$i]->id;?>">Edit</a></td> -->
                                      <!--<td><?php echo anchor('Category_retrieve/edit_data/'.$cust_details[$i]->id, ' Edit');?></td> -->
                                      <td><?php echo anchor('Category_retrieve/delete_data/'.$cust_details[$i]->id, ' Delete');?></td>
                                </tr>

                           <?php } ?>


                  </tbody>
              </table>

1 个答案:

答案 0 :(得分:0)

控制器中的Chage。使用result()而不是result_array()以对象格式记录。因为您使用箭头操作符来访问成员。

public function customerRecive($cust_ID)
     {
          $ID_decript = base64_decode($cust_ID);
          $this->db->where('CustomerID', $ID_decript);
          $query=$this->db->get('gst_customermaster');
          $cust_details= $query->result();//get result in object format
          $data['cust_details'] = $cust_details;
          //print_r($cust_details);
          //load the department_view
          $this->load->view('category_link_details_view',$data);

     }

有关详情,请参阅文档https://www.codeigniter.com/userguide3/database/results.html