¿Cómo puedo hacer que un archivo de idioma esté disponible para todas las funciones? - 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?

mi controlador:

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(){       

}
}

preguntado el 09 de marzo de 12 a las 16:03

2 Respuestas

La siguiente solución me funciona:

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

respondido 10 mar '12, 01:03

How do you print something from the lang file in some view? It´s not working for me... - zesilva

I'm using echo $this->lang->line('key'); - witti

That only works if i load the language file in the specific function that loads the view i want to print the content. - zesilva

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

respondido 09 mar '12, 16:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.