Welcome Guest, Not a member yet? Register   Sign In
When loading a library in a library, how do you use the loaded library's functions?
#1

[eluser]CMCDragonkai[/eluser]
I have base_library loading test_library. And I am trying to access the functions in test_library from base_library.

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Base_library{

public $CI;

    public function __construct(){
    
    if(!isset($this->CI)){
       $this->CI =& get_instance();
    }
        
    $this->CI->load->library('test_library');
        
    $this->test_library->lol();
        
    }
    
}

test_library:

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Test_library extends Base_library{

    public function __construct(){
    
        parent::__construct();
        
    }
    
    public function lol(){
        echo 'lol';
    }
    
}

The "$this->test_library->lol();" doesn't work. There is an error about it being a non object.

I've tried $test_library->lol(), it also doesn't work.
#2

[eluser]InsiteFX[/eluser]
Did you try loading it in the Constructor?

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Base_library{

// this should be private
private $CI;

public function __construct(){

if(!isset($this->CI)){
$this->CI =& get_instance();

$this->CI->load->library('test_library');
}

$this->test_library->lol();

}

}

InsiteFX
#3

[eluser]wiredesignz[/eluser]
Why not just include the library and instantiate a new object?
#4

[eluser]CMCDragonkai[/eluser]
[quote author="InsiteFX" date="1295702007"]Did you try loading it in the Constructor?

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Base_library{

// this should be private
private $CI;

public function __construct(){

if(!isset($this->CI)){
$this->CI =& get_instance();

$this->CI->load->library('test_library');
}

$this->test_library->lol();

}

}

InsiteFX[/quote]

That is what I did.

Quote:Why not just include the library and instantiate a new object?

This is what I ended up doing, it's just easier if all my classes had access to each other's functions.




Theme © iAndrew 2016 - Forum software by © MyBB