Welcome Guest, Not a member yet? Register   Sign In
CI error: get_where() on a non-object
#1

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?
" If I looks more intelligence please increase my reputation."
Reply
#2

do you connect to any database?

in the db var is not the database object...
Reply
#3

(This post was last modified: 01-12-2017, 03:50 AM by wolfgang1983.)

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
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#4

Let us know you things went
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB