To access CodeIgniter's native resources within your library use the get_instance() function. This function returns the CodeIgniter super object.
Normally from within your controller functions, you will call any of the available CodeIgniter functions using the $this construct:
$this, however, only works directly within your controllers, your models, or your views. If you would like to use CodeIgniter's classes from within your own custom classes you can do so as follows:
First, assign the CodeIgniter object to a variable:
[php]$CI =& get_instance();[/php]
Once you've assigned the object to a variable, you'll use that variable instead of $this:
$CI = &get_instance(); $CI->load->helper('url'); $CI->load->library('session');
You'll notice that the above get_instance() function is being passed by reference:
$CI = &get_instance();
This is very important. Assigning by reference allows you to use the original CodeIgniter object rather than creating a copy of it.