zesilva
zesilva

Reputation: 47

How can i make a language file available for all functions? - codeigniter

I have a controller that loads a language file, but that language file is only available for the function where i loaded the file. How can i make it available for all functions without being necessary to do $this->lang->load('main'); in all functions?

my controller:

class Main extends CI_Controller{

function _construct(){
    parent::__construct();
    //$this->lang->load('main'); //already tryed here doesn't load
}

function index(){
    //$this->lang->load('main'); //if i do it here it's not available for the other functions

}


function homeL(){       

}

function homeR(){       

}

function messagesL(){       

}
function messagesR(){       

}
}

Upvotes: 0

Views: 167

Answers (2)

witti
witti

Reputation: 151

The following solution works for me:

class Main extends CI_Controller{

function _construct(){
    parent::__construct();
    $this->lang->load('main','language');
}

Replace 'language' with the language you want to use. Without the second parameter CI uses the language specified in the config.php.

In the documentation you can find further information incl. the folder structure you have to use http://codeigniter.com/user_guide/libraries/language.html

Upvotes: 1

user973254
user973254

Reputation:

I think it's "hook case", so use hooks to pre-loading your lang file

Upvotes: 0

Related Questions