CodeIgniter Forums
partial active records query inside a method - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: partial active records query inside a method (/showthread.php?tid=58706)



partial active records query inside a method - El Forum - 07-10-2013

[eluser]keevitaja[/eluser]
hi,

what is the best way to achieve following:

i need to run several where() and like() in active records before fetching them in more than one place. these where and like are allways same. what changes are the get() and result() type.

something like that:

Code:
class Myclass
{
function filters()
{
  if (something)
  {
   $this->db->where('something')
  }
  
  if (something)
  {
   $this->db->like('something')
  }
  
  if (something)
  {
   $this->db->like('something')
  }
  
  if (something)
  {
   $this->db->where('something')
  }
  
  return $this->db
}
}

$myclass->filters()->get('mytable')->result()
$myclass->filters()->where('somethign')->get('mytable')->result_array()



partial active records query inside a method - El Forum - 07-18-2013

[eluser]plain jane[/eluser]
A switch case would help in this case.