Automatically loading config and language files of the same name as controller - 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: Automatically loading config and language files of the same name as controller (/showthread.php?tid=10742) |
Automatically loading config and language files of the same name as controller - El Forum - 08-11-2008 [eluser]Daniel H[/eluser] Hi all What is the most straight-forward way to load a config and language file of the same name as the controller you're currently accessing, if the files exist? I assume this would involve extending the controller class or perhaps a hook? If anyone could give me some guidance on doing that I'd really appreciate it. Many thanks, Dan. Automatically loading config and language files of the same name as controller - El Forum - 08-11-2008 [eluser]xwero[/eluser] I would do it in the CodeIgniter/codeigniter.php file above this line Code: call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2)); Code: if(file_exists(APPPATH.'config/'.$class.EXT)) Automatically loading config and language files of the same name as controller - El Forum - 08-11-2008 [eluser]Daniel H[/eluser] Thanks xwero. Is there a way of doing it without changing the core file? I'd rather not do that. The language files issue is okay: users can't change the language, I simply use it as a repository of semi-static text rather than using a db! Automatically loading config and language files of the same name as controller - El Forum - 08-11-2008 [eluser]xwero[/eluser] You can do it with hooks Code: // config/config.php I rather work without hooks because i change the codeigniter.php file location in the index.php file so the original file is untouched. Automatically loading config and language files of the same name as controller - El Forum - 08-11-2008 [eluser]Daniel H[/eluser] Many thanks - I'll try it both ways and figure out what I feel most comfortable with. |