CodeIgniter Forums
$this->db->get() returning an error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: $this->db->get() returning an error (/showthread.php?tid=37439)



$this->db->get() returning an error - El Forum - 01-10-2011

[eluser]Piero[/eluser]
Hey,

Following the second video tutorial, I've got this simple controller:

Code:
<?php
class Artist extends Controller {
    
    function Artist(){

        parent::Controller();

//        $this->load->scaffolding('artist');
        $this->load->helper('url');
        $this->load->helper('form');
    }

    function index() {
        
        $data['title'] = "Artist Title" ;
        $data['heading'] = "Artist Heading" ;
        
        $data['an_array'] = array("item1","item2","item3") ;

        $data['query'] = $this->db->get('artist') ;
        

        $this->load->view('artist/index', $data);
    }

}

?>

And when I call the page I've go this error:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Artist::$db
Filename: controllers/artist.php
Line Number: 22

Fatal error: Call to a member function get() on a non-object in /var/www/marie/system/application/controllers/artist.php on line 22

Since my class extends the Controller class, how come that $db is not recognized?
I don't get it...


$this->db->get() returning an error - El Forum - 01-10-2011

[eluser]Gerep[/eluser]
are you loading the database?


$this->db->get() returning an error - El Forum - 01-10-2011

[eluser]Bart Mebane[/eluser]
You need to load the database class before you can use it
Code:
$this->load->database();
or include it in your autoload.php file.


$this->db->get() returning an error - El Forum - 01-10-2011

[eluser]Piero[/eluser]
Sweet. It's working now.

Whether I missed it, whether it wasn't said clearly in the tutorial that you had to load it...

Thanks!