• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scopes within a view

#1
[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


Messages In This Thread
scopes within a view - by El Forum - 09-04-2008, 01:09 AM
scopes within a view - by El Forum - 09-04-2008, 01:28 AM
scopes within a view - by El Forum - 09-04-2008, 01:34 AM
scopes within a view - by El Forum - 09-04-2008, 11:01 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.