Welcome Guest, Not a member yet? Register   Sign In
How to Access Language from Helper
#1

[eluser]CodeIgniterNewbie[/eluser]
I have a helper that needs access to my language file. Language is already autoloaded and I can access it in the controllers just fine. However, in the helper, it seems I need to do this:

Code:
$codeigniter_intance =& get_instance();
$codeigniter_intance->lang->load('application', 'english');

And then access language elements this way:
Code:
$codeigniter_intance->lang->line('lang_label_profile_name')

Is this correct? Since the language file is already autoloaded, shouldn't my helper have access to it already? Thanks.
#2

[eluser]danmontgomery[/eluser]
You don't need to reload the language, but you do need to call get_instance() to get access to the CI object.

Code:
$CI =& get_instance();
echo $CI->lang->line('some_line');

Unless you have the language helper loaded:

Code:
echo lang('some_line');
#3

[eluser]CodeIgniterNewbie[/eluser]
Not working for me, though. Here's a snippet of actual code:

Code:
$codeigniter_intance =& get_instance();
// $codeigniter_intance->lang->load('application', 'english');

$config['validations']['profile_update'] = array(
    array(
        'field' => 'name',
        'label' => $codeigniter_intance->lang->line('lang_label_profile_name'),
        'rules' => 'trim|required|xss_clean'
    ),

With the language loading commented out, I get nothing for label. If I uncomment it, 'label' gets what is specified in the language file. I've double checked, I am autoloading the 'application' language file:

Code:
$autoload['language'] = array('application');

What could I be doing wrong?
#4

[eluser]CodeIgniterNewbie[/eluser]
Ugh. I just realized I am trying to access language lines from config and NOT from the helper. How do I access language lines from config? Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB