CodeIgniter Forums
First project: Model problem - 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: First project: Model problem (/showthread.php?tid=14850)



First project: Model problem - El Forum - 01-17-2009

[eluser]webnology[/eluser]
Hi all,

this is my first project, so I might start to ask some silly questions. Here I go.

I try to execute a function from my model, getNumberOfArtists.

My model is like this:

Code:
class Artists extends Model {
    function Artists() {
        parent::Model();
    }
}

//Get nr of artists in atg
function getNumberOfArtists() {
    $Q = $this->db->query('SELECT * FROM atg_bands');
    $nr_artists = $Q->num_rows();
    return $nr_artists;
}

The model is called artists.php

My COntroller looks like this:

Code:
class Home extends Controller {
    //Constructor
    function Home() {
        //Controller is our parent Class
        parent::Controller();
            //Load helpers
        $this->load->helper('url');
        $this->load->helper('form');
    }
    
    function index() {

        //Load artists model
        $this->load->model('artists');
        $data['nr_artists'] = $this->artists->getNumberOfArtists();
        
    }

}

The eroor I get is: Fatal error: Call to undefined method Artists::getNumberOfArtists() in /var/www/..../application/controllers/home.php on line 27

Could anyone help me please?

Kind regards,
M


First project: Model problem - El Forum - 01-17-2009

[eluser]Sarfaraz Momin[/eluser]
The model code is incorrect. You are closing the class before the getNumberOfArtists method. Please check the code below.

Code:
class Artists extends Model {
    function Artists() {
        parent::Model();
    }

   //Get nr of artists in atg
   function getNumberOfArtists() {
       $Q = $this->db->query('SELECT * FROM atg_bands');
       $nr_artists = $Q->num_rows();
       return $nr_artists;
   }
}

Have a good day !!!


First project: Model problem - El Forum - 01-17-2009

[eluser]webnology[/eluser]
Thx man! As I said, not too smart for now!