fabrizio
fabrizio

Reputation: 259

Call to undefined method codeigniter

where i'm doing mistake? I tried to solve it, but nothing. I did all right, is the first time I have this error.

 Fatal error: Call to undefined method Team_model::exist_team() in C:\wamp\www\example\application\libraries\teams.php on line 28

This is my library:

class Teams { // My class

    function __construct()
    {
        $this->ci =& get_instance();
        $this->ci->load->model('team_model');
    }


    function exist_team($team_id) { // this function give me that error

        if ($query_get_info = $this->ci->team_model->exist_team($id_team)) { // line with error
            return $query_get_info[0];
        } else {
            return false;
        }
    }

}

This is my model

class Team_model extends CI_Model {

    function exist_team($id_team) { // function exixst team in library
        $this->db->select('*');
        $this->db->from('teams');
        $this->db->where('url',$id_team);
        $query = $this->db->get();
        if ($query->num_rows() == 0) {
            return false;
        } else {
            return $query->result();    
        }
    }
}

Upvotes: 0

Views: 29191

Answers (2)

Vrushal Raut
Vrushal Raut

Reputation: 1208

Check for spelling mistakes of Models name, if there is any spelling mistakes or distinct name from original model show error of Undefined Method.

Upvotes: 1

Dustin Brownell
Dustin Brownell

Reputation: 815

I was able to run this on a clean CI install without errors. Here's what I would check:

  1. Make sure you're file names for both the model and library are capitalized. (Team_model.php & Teams.php). *Note -- Codeigniter Docs state that only the Library names must be capitalized, but using the current version on GitHub, the load fails unless both files were capitalized.

  2. Declare the CI variable outside the constructor scope. This shouldn't be an issue, but it's worth exploring.

    class Teams { 
      private $_ci;
    
      function __construct()
      {
        $this->_ci =& get_instance();
        $this->_ci->load->model('team_model');
      }
    }
    

Unrelated, but an error: You use $team_id then $id_team.

function exist_team($team_id) {

if ($query_get_info = $this->ci->team_model->exist_team($id_team)) {

Upvotes: 2

Related Questions