![]() |
globals in functions in views - 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: globals in functions in views (/showthread.php?tid=4921) |
globals in functions in views - El Forum - 12-23-2007 [eluser]zauber[/eluser] It appears that one can not use global variables in functions in views. See this example: Code: testview.php This outputs "10", ie: outside the function, the variable "tree" is set (passed from the controller), but inside the function the variable is NOT set, despite using "global". Why don't globals work in functions in views? Are there any other "hidden" ways in which views are not just plain, normal php scripts? globals in functions in views - El Forum - 12-23-2007 [eluser]tonanbarbarian[/eluser] the issue is that you are assuming any variable that is declared in the view is global... it is not. it has to do with how views are coded it also explains why you always pass data to helpers in the view rather than letting the helper grab the data from global, because it will not be there |