我正在将参数从模型传递给这样的视图
模型
class school_model extends CI_Model{
function employee_get($student_id){
$query = $this->db->get_where('students', array('student_id'=>$student_id));
return $query->row_array();
}
}
控制器
function bret($student_id){
$this->load->model('school_model');
$data = $this->school_model->employee_get($student_id);
echo $data['student_gender'];
}
这显然转化为select * from students where id=id
给定的例子,并且通过浏览器可以看到http://example.com/env/at/index.php/frontpage/bret/306
我想知道是否get_where()
适合我是否要进行此查询
select student_gender,student_has_a_medical_condition from students where (student_gender = 'female' && student_has_a_medical_condition = 'no') LIMIT 40;
我需要扩展get_where()
它才能工作吗?
首先,我建议阅读ActiveRecord类上有关CodeIgniter的出色文档。
您不必扩展,get_where()
而只需使用现有方法来定义您的查询:
function employee_get($student_id){
$this->db->select('student_gender','student_has_a_medical_condition');
$query = $this->db->get_where('students', array('student_id'=>$student_id,'student_has_a_medical_condition'=>'no','student_gender'=>'female'),40);
return $query->row_array();
}
当然,您可以将其他参数传递给该函数,这样就不会对其进行硬编码,并且还可以将所需的列作为参数表传递。但是从文档开始。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句