I want to call a function in a library inside another library which is written by me. Is it possible to do this in codeigniter? If so, can anyone explain how to do that?
You could do;
$CI =& get_instance();
$CI->load->library('your_library');
$CI->your_library->do_something();
Typically, you reference the Codeigniter object (the current controller, technically) by using get_instance()
. Often you'll want to assign it to a property of your library, like this:
class My_Library {
private $CI;
function __construct()
{
// Assign by reference with "&" so we don't create a copy
$this->CI = &get_instance();
}
function do()
{
$var = $this->CI->my_other_library->get();
// etc.
}
}
Just make sure the other library is loaded or in your config/autoload.php
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With