Am i misunderstanding something?
Say i have model method below:
public function product($user_id,$action){
$this->db->select('product_id');
$this->db->from('products');
$this->db->where('user_id', $user_id);
$query = $this->db->get();
$counter = 0;
switch($action){
case 'ids':
foreach($query->result() as $row){
data['ids'][$counter] = $row->product_id;}
return $data;
break;
case 'count':
return $query->num_rows();
break;
}
}
Is the above considered a reusable method since i can use it for 2 purposes?
Or is it not, and is it better to just separate them into two single methods?
Is a reusable method more like this:
public function get_id($table,$value){
$id = $table.'_id';
$query = $this->db->get_where($table, array($id => $value));
}
I use simple names for my table and the PK(ID). For example, 'user' table would have 'user_id'. 'product' table would have 'product_id'