【问题标题】:Code igniter model function call issueCodeigniter 模型函数调用问题
【发布时间】:2016-04-08 10:18:59
【问题描述】:

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 
        }
    }
}

【问题讨论】:

  • 在函数名前使用 $this-> 如 $this->checkReligion($religion)
  • 简单的错误。作品

标签: php codeigniter


【解决方案1】:

在您的类中调用同一类中其他方法中的方法,在方法之前使用$this-&gt;

  $this->checkReligion($religion) ;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    相关资源
    最近更新 更多