0
我已經創建了一個通用模型函數來從Mysql中獲取數據。我可以對所有選擇的數據使用此功能。如何簡化codeigniter中的模型函數
//Controller
$where = array('user_id' => 1);
$data['all_rewards'] = $this->select->selectData('tbl_example1', $where, null, 'user_id', 10, 1);
//Model
public function selectData($table, $where, $group_by, $order_by, $limit, $start) {
$this->db->select('*');
$this->db->from($table);
if(!empty($where))
$this->db->where($where);
if(!empty($group_by))
$this->db->group_by($group_by);
if(!empty($order_by))
$this->db->order_by($order_by, 'DESC');
if(!empty($limit) or !empty($start))
$this->db->limit($limit, $start);
$query = $this->db->get();
return $query->num_rows() > 0 ? $query->result_array() : 0 ;
}
上述代碼工作正常。
只是我想知道是否有任何簡化的方法,而不是我的函數從數據庫中選擇數據。而且我的方法是否正確。