CodeIgniter Forums
CI error: get_where() on a non-object - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: CI error: get_where() on a non-object (/showthread.php?tid=67065)



CI error: get_where() on a non-object - davy_yg - 01-11-2017

Hello,

I am receiving this error messages:


Fatal error: Call to a member function get_where() on a non-object in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\models\gallery_model.php on line 10

line 10:  
Code:
 $query = $this->db->get_where('galleries_pictures',array('pic_id'=> $pic_unique_id));


model:
Code:
class Gallery_model extends CI_Model {
   public function get_picture($pic_unique_id)
   {
       $query = $this->db->get_where('galleries_pictures',array('pic_id'=> $pic_unique_id));
       return $query->result();
   }
}

controller:
Code:
public function index()
{
  $this->load->helper('url');
   $this->load->model('gallery_model');//loads model
   $data['pic']  = $this->gallery_model->get_picture($pic_unique_id);//calls to model function
   $this->load->view('index',$data);//loads view with data
}


view:
Code:
<?php foreach($pic as $pic_item) { ?>
<img src="<?php echo base_url(assets1/images/slider/).$pic_item->pic_item; ?>">
<?php } ?>

I wonder how to fix the error message?


RE: CI error: get_where() on a non-object - Paradinight - 01-11-2017

do you connect to any database?

in the db var is not the database object...


RE: CI error: get_where() on a non-object - wolfgang1983 - 01-12-2017

Did you autoload the database library



PHP Code:
$autoload['libraries'] = array('database'); 


Your file name is also incorrect should have first letter upper case only

Change

gallery_model.php

To

Gallery_model.php


RE: CI error: get_where() on a non-object - wolfgang1983 - 01-12-2017

Let us know you things went