How to use a library in the MY_Loader-Class

#1
[eluser]axelf[/eluser]
Hi,

i want to use a library in the MY_Loader Class. How can i load this library into the MY_Loader-Class?

The Library is named Language and is in application/libraries/Language.php. In autoload.php i added 'language' in $autoload['libraries']-array. In the My_Loader Class i want to use $this->language, but it does not work. What i am doing wrong?

Code:
class MY_Loader extend CI_Loader {
  public function language_view() {
    $this->language->get(); // Message: Undefined property: MY_Loader::$language
  }
}

#2
[eluser]Tpojka[/eluser]
Add the constructor.
Code:
class MY_Loader extend CI_Loader {
  public function __construct() {
    parent::__construct();
  }

  public function language_view() {
    $this->language->get(); // Message: Undefined property: MY_Loader::$language
  }
}

#3
[eluser]axelf[/eluser]
Hi,

this is my Loader Class. It dosn't work with the constructor. i have to use the CI-Objekt, but why? The Library will be loaded automatically, but now i have to load this in the class?

Code:
// config:
$autoload['libraries'] = array('database','form_validation','session','email','language');

class MY_Loader extends CI_Loader {

    function __construct() {
        parent::__construct();
    }

    function lang_view($view, $vars=array()) {
        // this works
        //$CI =& get_instance();
        //$CI->load->library('language');
        //$lang = $CI->language->get();
        
        // this does not work
        $lang = $this->language->get()        
    }
}

#4
[eluser]Tpojka[/eluser]
Only explanation is that file is loaded after controller.

#5
[eluser]axelf[/eluser]
Hi,

thank you for helping.
Using the CI-Object is the right way?

#6
[eluser]Tpojka[/eluser]
User guide perfectly agrees. Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.