I’m storing user language in session, and then I’m loading the language file like this:
$language = $this->session->userdata('language');
$this->lang->load('form_validation', $language);
But its pretty annoying, when I have to load the above $language variable in every controller, it would be better if it would be a global variable, so I could use just:
$this->lang->load('form_validation', $language);
- Where
$languagevar would be a global variable.
How can I do that?
If you’re really wanting a one-liner then why not just do
As for globals in general it’s usually not a good practice to create them unnecessarily. The reason being that globals by nature can be accessed from anywhere so it’s possible to update them from anywhere which can lead to hard to find bugs