代码点火器模型函数调用问题

时间:2016-04-08 10:19:00

标签: php codeigniter

CodeIgniter模型具有以下功能。无法从内部模型调用另一个函数。当我试图调用函数checkReligion它说错误

  

调用未定义的函数checkReligion()

class maindata_model extends CI_Model {
    function get_data_all($gender, $age_min, $age_max, $religion) {  
        $this->db->select('*');          
        if($gender == 1) { 
            $this->db->where('gender', 'F');            
            $this->db->where('age >=', $age_min);             
            $this->db->where('age <=', $age_max);  
            checkReligion($religion) //unable to call from here     
        }
        elseif($gender == 2) {
            $this->db->where('gender', 'M');            
            $this->db->where('age >=', $age_min);             
            $this->db->where('age <=', $age_max);
            checkReligion($religion)  //unable to call from here               
        }      
        else{
            redirect(base_url());
        }        
        $query = $this->db->get('tble_students');        
        if ($query->num_rows() > 0) {            
            echo(json_encode($query->result()));          
            exit();            
        } else {            
            return false;
        }
    }
    function checkReligion($religion) {
        if ($religion == 1) {
            $rTypes = array(2, 3, 4, 5, 6);
            $this->db->where_in('religion', $rTypes);   //display all religions 
        } else {
            $this->db->where_in('religion', $religion); //display one religion 
        }
    }
}

1 个答案:

答案 0 :(得分:1)

在Class中,要在同一个类的其他方法中调用该方法,请在方法

之前使用$this->
  $this->checkReligion($religion) ;