Welcome Guest, Not a member yet? Register   Sign In
codeigniter load library from within library
#1

[eluser]haily_php[/eluser]
In codeigniter, what can I do to load library from within library?
Please help me.
#2

[eluser]InsiteFX[/eluser]
Code:
private $CI;

public __construct()
{
    $this->CI = get_instance();
    $this->CI->load->library('library_name');
}

// then to access use
$this->CI->library_name->method();

InsiteFX
#3

[eluser]bientek[/eluser]
get_instance seems to be undefined in the context of a library that replaces a CI native library. For example, in MY_Log...
Code:
function MY_Log()
{
    parent::CI_Log();
    $CI =& get_instance();
    $CI->load->library('test');
}

...produces: "Fatal error: Call to undefined function get_instance()..."
#4

[eluser]CroNiX[/eluser]
your parent::CI_Log() should be parent::__construct(), and it should be in a __construct() itself, just like InsiteFX showed you. See the manual for Creating Libraries, especially the Replacing Native Libraries with Your Versions section

You aren't extending/replacing the native library correctly.
#5

[eluser]bientek[/eluser]
Sorry, that's 1.7.2 code there. Regardless, one still cannot use get_instance() when replacing a native library, at least in this case.
#6

[eluser]InsiteFX[/eluser]
It works here just fine.




Theme © iAndrew 2016 - Forum software by © MyBB