Search code examples
codeignitercodeigniter-2

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();    
        }
    }
}

Solution

  • 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)) {