CodeIgniter Forums
How to call libraries in config file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forum-11.html)
+--- Thread: How to call libraries in config file (/thread-67905.html)



How to call libraries in config file - ardavan - 04-21-2017

Hi,

I've made a general menu array in app_config.php to call it easily anywhere on my controllers.
Now i decided to have multilingual functionality for my app and i cant use $this->lang->line('my_menu_name') in the config file.

PHP Code:
$config['menu'] = array(
 
$this->lang->line('profile') => '/profile',
 
'Settings'          => '/settings',
); 

Is there any way to make this happen? (I can't change the menu array place - should be in app_config.php)

Thanks guys


RE: How to call libraries in config file - JayAdra - 04-21-2017

I would just use an English key in the config array, i.e. "profile" and then on the view side of things, call the lang line, e.g.

PHP Code:
foreach($config['menu'] as $key => $value) {
    echo 
$this->lang->line($key);




RE: How to call libraries in config file - ardavan - 04-22-2017

(04-21-2017, 09:33 PM)JayAdra Wrote: I would just use an English key in the config array, i.e. "profile" and then on the view side of things, call the lang line, e.g.

PHP Code:
foreach($config['menu'] as $key => $value) {
 echo 
$this->lang->line($key);


Thats a good idea and works for my menu names. but i have another arrays which the first item is like
PHP Code:
$config['country'] = array(
    
''                        =>    'Pick a Country'

And im using the array like this
PHP Code:
echo form_dropdown(array(
   
'name'            =>    'country',
   
'placeholder'    =>    $this->lang->line('placeholder_country'),
   ),
   
$country,
   
set_value('country'$get_user->COUNTRY)
   ); 

How can be translate the 'Pick a Country' ?


RE: How to call libraries in config file - JayAdra - 04-23-2017

Again, only use keys in the config arrays.

In your view, simply call something like:

PHP Code:
$this->lang->line('placeholder_' $key);