[eluser]ggoforth[/eluser]
Hello All, just a quick question about the scope of functions within a view. I was having an issue accessing a config item in the main config file, when calling from a function within a view. So my code below does not work:
------ VIEW FILE -----
Code:
<?php
//this code fails
function echoConfigItem(){
$item = $this->config->item('some_array_key');
echo $item;
}
echoConfigItem();
?>
However, the code below does work:
------ VIEW FILE -----
Code:
<?php
define('SOME_GLOBAL_VAR',$this->config->item('some_array_key'));
function echoConfigItem(){
echo SOME_GLOBAL_VAR;
}
echoConfigItem();
?>
So, when I call the config item from outside the function in the view, everything works fine. I will say I solved the problem using the second method, I'm just curious about why I can't call the $this->config->item() function from within a function in a view.
Thanks all!
Greg