Welcome Guest, Not a member yet? Register   Sign In
accessing config variables from helpers or library
#1

[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
doesnot seem to work.
#2

[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.
#3

[eluser]überfuzz[/eluser]
Jeremy is spot on. You'll reach a config-item like this.
Code:
$this->config->item('your_constant');
config.php
Code:
$config['your_constant'] = "Holy molly, it's working";
#4

[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();

$CI->config->item('base_url');
#5

[eluser]Colin Williams[/eluser]
Use the config_item() function, which is available globally
#6

[eluser]Jeremy Gimbel - Conflux Group[/eluser]
You learn something everyday!

Didn't know that.




Theme © iAndrew 2016 - Forum software by © MyBB