![]() |
accessing config variables from helpers or library - 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: accessing config variables from helpers or library (/showthread.php?tid=24599) |
accessing config variables from helpers or library - El Forum - 11-13-2009 [eluser]oliur[/eluser] Does anyone know how to use a variable in Quote:System/Helpers/filename.php (could be any of the helper files)which has been set in Quote:Application/config/filename.php (could be any of the config files) Code: $this->varible accessing config variables from helpers or library - El Forum - 11-29-2009 [eluser]Jeremy Gimbel - Conflux Group[/eluser] Helpers do not have direct access to the CodeIgniter object. You'll need to either pass data in through the parameters of the function or consider moving the code to a Model, Controller or Library accordingly for its purpose. Helpers are generally just used to do very general-purpose tasks that don't require access to the data and variables in the rest of the applications's objects. accessing config variables from helpers or library - El Forum - 11-30-2009 [eluser]überfuzz[/eluser] Jeremy is spot on. You'll reach a config-item like this. Code: $this->config->item('your_constant'); Code: $config['your_constant'] = "Holy molly, it's working"; accessing config variables from helpers or library - El Forum - 11-30-2009 [eluser]Jeremy Gimbel - Conflux Group[/eluser] And further, if you're using a library, instead of a controller or model, you won't have direct access to the CodeIgniter instance. You'll have to use code like this, instead of the standard $this->config->item(...); Code: $CI =& get_instance(); accessing config variables from helpers or library - El Forum - 11-30-2009 [eluser]Colin Williams[/eluser] Use the config_item() function, which is available globally accessing config variables from helpers or library - El Forum - 11-30-2009 [eluser]Jeremy Gimbel - Conflux Group[/eluser] You learn something everyday! Didn't know that. |