Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Call to a member function get() on a non-object in C:\wamp\www\ci\application\models\site_model.php on line 6

Hello I just watched the first/Day1 screencast on Nettuts "CodeIgniter from scracth" And I'm already running into an error I don't understand. Here's a screenshot http://i39.tinypic.com/14mtc0n.jpg

The code in my models\site_model.php is the same as the screencast

   models\site_model.php

   class Site_model extends CI_Model {  
   function getAll() {
    $q = $this->db->get('test');        
    if($q->num_rows() > 0) {
        foreach ($q->result() as $row) {
            $data[] = $row;
        }
    return $data;
    }
}

And the controller controllers\site.php

   class Site extends CI_Controller {
function index(){
    $this-> load-> model('site_model'); 
    $data['records'] = $this-> site_model-> getAll();
    $this-> load-> view('home', $data);

}   
 }

And here's my db info incase

 $db['default']['hostname'] = 'localhost';
 $db['default']['username'] = 'root';
 $db['default']['password'] = '';
 $db['default']['database'] = 'ci_series';
(rest is default below)

Thank you

like image 279
Matt Avatar asked Dec 16 '22 03:12

Matt


1 Answers

You need to load the database first. Codeiginiter won't load it by default for you.

You can either add it to /config/autoload.php like so

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

Or you can load it on demand whenever you want by calling

$this->load->database();

More details here

http://codeigniter.com/user_guide/database/connecting.html

like image 138
JohnP Avatar answered Jan 11 '23 23:01

JohnP