CodeIgniter Forums

Full Version: Accessing a custom library's function in a helper
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Is this even possible? If so, what is the code required for it?

When I think of using the load, to me it only makes sense if it is used inside a class, but a helper is not a class but a group of functions.

Would I need to use 'new' instead? If so, how?

El Forum

If you want to use a function that is inside a library, you need to load the library and then use something like:

# Load the library.

# Use the function...

This answers your question?


- G l a z z

El Forum

If its from a helper, you need to reference the CI superglobal, just like you do when creating libraries that use CI.
function some_helper()
  //grab our CI instance
  $CI =& get_instance();
  //use normally using the new reference

  $data = $CI->some_library->some_method();

Or, if you have already loaded the library in CI, you can reference it in your helper after grabbing the ci instance.

function some_helper($data)
  $CI =& get_instance();
  //library is already loaded in the controller before the helper, just access it