0

このようにモデルからビューにパラメーターを渡しています

モデル

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()ますか?

4

1 に答える 1

2

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

もちろん、ハードコードされないように追加のパラメーターを関数に渡すことができます。また、必要な列をパラメーターとして渡すこともできます。しかし、ドキュメントから始めましょう。

于 2013-07-05T15:52:01.733 に答える