我正在使用函數來設置整個sql查詢。 這個函數被其他兩個用來獲取sql,然後根據需要使用它。清除CodeIgniter中的SELECT字段
現在,我想要另一個函數來執行相同的查詢,但我不需要以前的函數需要的所有字段。所以,我想知道是否有方法在設置後替換查詢的SELECT部分。
僞代碼:
function sql(){
$this->db->select('*');
$this->db->from('table');
}
function defaultSql(){
$this->sql();
$this->get();
}
function notAllFields(){
$this->sql();
// This is the solution I'm looking for. It should clear the select
$this->db->clearSelect();
// I define a different select
$this->db->select('field');
$this->get();
}
提前感謝!
請注意,我正在尋找一種解決方案,實際上可以清除已設置的選擇。我的源代碼比示例複雜得多,所以我不想將任何參數傳遞給sql函數。 ;) – j4nSolo 2013-05-13 08:40:34