Search code examples
phpcodeigniterrecursioncontrollerhelper

Can CodeIgniter Helper Functions use database functions?


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?


Solution

  • You can get instance:

     $CI =& get_instance();
    

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