Global variables, set defined variables - 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: Global variables, set defined variables (/showthread.php?tid=9990) |
Global variables, set defined variables - El Forum - 07-15-2008 [eluser]bigdaddysheikh[/eluser] Hey guys, I have been searching for this topic for quiete sometime and have not found what I am looking for. So here it goes. I keep having undefined errors from CI. Although it is not PHP errors, I know it is bad practice. First, is there a way to define these variables in the controller so it can be sent through different functions. Currently, I am trying to use a variable that will hold URLS that I want to display in many sub functions of the mother controller. Rather than me declaring this variable in every function, how can I set this variable only once. Last but not least, is there a better way to pass arrays to views. example Code: $data["foo"][0] = "test"; I did try this, but it does not work: Code: $data["foo"] = "test"; Global variables, set defined variables - El Forum - 07-15-2008 [eluser]Colin Williams[/eluser] Code: $data["foo"][] = "test"; That ought to work. It will be $foo[0] and $foo[1] in your view. If I'm going to be sharing variable throughout different areas of an application, I'll usually just create a config file for it and load it with the Config class. |