试图获取非对象Filename:views / galleries_pictures.php的属性

时间:2016-11-18 06:21:06

标签: codeigniter

我想知道如何修复此错误消息?

  

遇到PHP错误

     

严重性:注意

     

消息:尝试获取非对象的属性

     

文件名:views / galleries_pictures.php

     

行号:69

模型/ Mpages.php

public function add_picture_gallery($filename, $gallery_id)
{   

    $data = array(
        'galleryies_id' => $gallery_id,
        'galleries_picture_name' => $filename,
    );

    $query = $this->db->insert('galleries_pictures', $data);
    return $query->result();

}   

HTML

<tr>                                
    <td><img src="<?php echo base_url();?>uploads/<?php echo $pictures_item->galleries_picture_name; ?>" height="200" width="300"></td>
    <td><?php echo $pictures_item->galleries_picture_name; ?></td>
    <td><button type="button" class="edit">EDIT</button></td>
    <td><button type="button" class="delete">DELETE</button></td>
</tr>

1 个答案:

答案 0 :(得分:0)

首先你需要select。不是insert

试试这种方法。

控制器中的

$data['image_list'] = $this->ur_Model->get_image_list();
$this->load->view('ur_view_filename', $data);
模型中的

public function get_image_list()
  {
    $this->db->select('*');
    $this->db->from('ur_table');    
    return $this->db->get();
  }

在视图

<table>
  <?php foreach ($image_list->result() as $pictures_item) { ?>
    <tr>                              
      <td><img src="<?php echo base_url();?>uploads/<?php echo $pictures_item->galleries_picture_name; ?>" height="200" width="300"></td>
      <td><?php echo $pictures_item->galleries_picture_name; ?></td>
      <td><button type="button" class="edit">EDIT</button></td>
      <td><button type="button" class="delete">DELETE</button></td>
    </tr>
  <?php } ?>
</table>