Can CodeIgniter Helper Functions use database functions?

Rorrik picture Rorrik · Apr 8, 2013 · Viewed 24.5k times · Source

One of my CodeIgniter Controller functions needs to call a recursive function as part of its functionality. The function call chokes if I put it inside the controller class, and it can't access database functions ($this->db->get()) if I put it outside the class. Would making it a helper function fix this problem?

Answer

Svetoslav picture Svetoslav · Apr 8, 2013

You can get instance:

 $CI =& get_instance();

After that you will be able to use $CI->db for queries..