Welcome Guest, Not a member yet? Register   Sign In
First project: Model problem
#1

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB