![]() |
create dynamic variable in config.php - 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: create dynamic variable in config.php (/showthread.php?tid=57207) |
create dynamic variable in config.php - El Forum - 02-26-2013 [eluser]marine[/eluser] Hello, I want use dynamic variable in file config.php. It's for creating a multilingue website and I want stock all language in a database and use this information for my variable in config.php (for example for $config['language']). I don't found how we can access on database in config.php. Can you please help me? :-) Marine ps : excuse me if my english is not good but I'm french! ;-) create dynamic variable in config.php - El Forum - 02-26-2013 [eluser]Eduard Stankovic[/eluser] yes it is a possible .. try something like this in MY_controller or MY_lang.... it is up to you... but try to use i18n library ![]() Code: global $CFG; or Code: $this->config->set_item('language', 'slovak'); I hope it's what are you looking for ![]() create dynamic variable in config.php - El Forum - 02-26-2013 [eluser]marine[/eluser] Thank you for your response. But it's not really that. I explain more : in my file application/config/config.php I have some language variable : /* default language */ $config['language'] = "french"; /* default language abbreviation */ $config['language_abbr'] = "fr"; /* set available language abbreviations */ $config['lang_uri_abbr'] = array("en" => "english", "fr" => "french"); /* hide the language segment (use cookie) */ $config['lang_ignore'] = FALSE; I want stock my language information in database for edit and add language from back office. So, when I edit or add an information language, I need see this language in $config['lang_uri_abbr']. So I want define $config['lang_uri_abbr'] in config.php with database information. But if I use $ci = &get;_instance() it's doesn't work... So I don't know how access database from config.php. Are you understand? Thanks again for your help! :-) create dynamic variable in config.php - El Forum - 02-26-2013 [eluser]CroNiX[/eluser] You can't because config loads very early on in the bootstrap process and the db object isn't available yet. See /core/CodeIgniter.php to see how and the order that the CI objects are loaded/used. I would create a base controller, MY_Controller, and set your lang def there in the __construct(). Then have all of your other controllers extend that base controller instead of CI_Controller so it will be available to everything (including your database). You also might be able to using a hook, but I think that would be pretty inefficient for this. create dynamic variable in config.php - El Forum - 02-27-2013 [eluser]marine[/eluser] Hello, thank you for your help. I try to modified variable from MY_Controller but it don't function. I found an other solution, not the best I imagine but this solution function for the moment! I connect database with php like : Code: mysql_connect("server", "login", "password"); // Connexion à MySQL thanks again for your help. |