CodeIgniter Forums
Using config item in language file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Using config item in language file (/showthread.php?tid=42323)



Using config item in language file - El Forum - 06-03-2011

[eluser]bhumes[/eluser]
Is it possible to use a config item in a language file?

I have this in my application/config/config.php file:
Code:
$config['settings.tollfree']  = '00 800 4263 7393';

and in my application/languages/english/all_lang.php file:
Code:
$lang['call_us'] = "Please call us at ".$this->config->item('settings.tollfree').".";

When I run it, I get this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Lang::$config
Filename: english/all_lang.php
Line Number: 204 <-- this is the above line #

I am assuming this has to do with the order things are loaded in CI. Is there anything I can do about this? Any advice?

Thanks a million!


Using config item in language file - El Forum - 06-03-2011

[eluser]John_Betong_002[/eluser]
Here is a quick KLUDGE until you find a better solution.

Code:
// application/config/config.php
  const SETTINGS_TOLLFREE = '00 800 4263 7393';

  // application/languages/english/all_lang.php file:
  $lang['call_us'] = "Please call us at ".SETTINGS_TOLLFREE .".";
&nbsp;
&nbsp;


Using config item in language file - El Forum - 06-03-2011

[eluser]Armchair Samurai[/eluser]
Here's another way to do it:

Code:
//In your language file
$lang['call_us'] = 'Please call us at %s.';

//When you need the string
printf($this->lang->line('call_us'), $this->config->item('settings.tollfree'));