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

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

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


   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 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 is my db info incase

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




source to share

2 answers

First you need to load the database. Codeiginiter will not download it by default for you.

You can either add it to the /config/autoload.php

way how to do it

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


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



More details here




Add a constructor to you if you havenot:

class Site_model extends CI_Model {  

    function __construct()


And: database autoload by modifying app /config/autoload.php if you don't have autoload



All Articles