Defining variables to be used throughout a controller - 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: Defining variables to be used throughout a controller (/showthread.php?tid=20211) |
Defining variables to be used throughout a controller - El Forum - 07-01-2009 [eluser]Fielder[/eluser] I have a variable say $var that is used throughout the entire controller. How do I define it at the beginning of the controller so I can call it anywhere in any function in the controller? Is this correct? Code: <?php And second to that, what if I wanted a function to perform a task to create a variable, but I didn't want to return it. I just wanted the results of the function to be available anywhere else in the controller. Code: function open() I've tried just this and it doesn't work... I suspect something having to do with how the controller is setup.? Thanks. Defining variables to be used throughout a controller - El Forum - 07-01-2009 [eluser]Thorpe Obazee[/eluser] Code: class ContractStore_Form extends Controller{ Defining variables to be used throughout a controller - El Forum - 07-01-2009 [eluser]JoostV[/eluser] And call it in methods using Code: // Change var Defining variables to be used throughout a controller - El Forum - 07-01-2009 [eluser]Colin Williams[/eluser] And you are doing Code: $final = $this->rowopen . $this->rowclose; Code: $final = $this->open() . $this->close(); Defining variables to be used throughout a controller - El Forum - 07-01-2009 [eluser]tonanbarbarian[/eluser] [quote author="Colin Williams" date="1246530677"] Code: $final = $this->open() . $this->close(); This will not work because the open and close methods are not returning anything, however open and close must both be called before you can access their values Code: $this->open(); Defining variables to be used throughout a controller - El Forum - 07-01-2009 [eluser]Colin Williams[/eluser] Bah!... Thanks for righting my wrong, tonanbarbarian Defining variables to be used throughout a controller - El Forum - 07-02-2009 [eluser]xwero[/eluser] for the rowopen, rowclose and i guess cellcloseopen and emptyrow why not use globals as you are going to use then on each page where a form is. you can add those to the config/constants.php file. |