![]() |
Controller Class 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: Controller Class Variables (/showthread.php?tid=8515) |
Controller Class Variables - El Forum - 05-20-2008 [eluser]bennyhill[/eluser] for my main controller, I have a bunch of reoccurring variables in each function in the class. For example, Code: $data['css'] = $this->config->item('css') example Code: class Catalog extends Controller{ Controller Class Variables - El Forum - 05-20-2008 [eluser]gtech[/eluser] Code: class Catalog extends Controller{ Controller Class Variables - El Forum - 05-20-2008 [eluser]Pascal Kriete[/eluser] Small addition. You need to define it as a class variable. Code: class Catalog extends Controller{ Controller Class Variables - El Forum - 05-20-2008 [eluser]bennyhill[/eluser] I tried your example multiple different ways to no success. All I get is a blank screen in the browser and when I view source there is nothing there. When I comment out the line Code: $this->data = new array(); Controller Class Variables - El Forum - 05-20-2008 [eluser]bennyhill[/eluser] I got it. Just had to delete the line $this->data = new array(); For some reason I didn't need it. Controller Class Variables - El Forum - 07-23-2008 [eluser]phpworker[/eluser] Gosh, but.... WAIT! The 'new' operator is not for array initialization, I suppose? ![]() Controller Class Variables - El Forum - 07-23-2008 [eluser]nmweb[/eluser] 'new' only applies to objects and arrays are not objects in php unless you use spl in php5. Class properties in php4 are public so you can always access them, even from outside the object. Controller Class Variables - El Forum - 07-23-2008 [eluser]thinkigniter[/eluser] Yep! new Array(); is Javascript php is just the plain and simple $var = array(); Controller Class Variables - El Forum - 07-23-2008 [eluser]nmweb[/eluser] It's a pity though that strings, integers and arrays etc. are not objects like they are in python. The syntax is way clearer + you extend types. I hope spl in php6 will solve this. |