Welcome Guest, Not a member yet? Register   Sign In
$this->db->get() returning an error
#1

[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...
#2

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

[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.
#4

[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!




Theme © iAndrew 2016 - Forum software by © MyBB