![]() |
Setting default variables in 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: Setting default variables in a controller (/showthread.php?tid=2076) |
Setting default variables in a controller - El Forum - 07-15-2007 [eluser]deineMudder[/eluser] Hello i am still a newbie to CI and have a basic question again. I got my Controller User: Code: <?php In order to define some variables im passing the controller to a library to return the variables i want. Now i want to reduce my code a bit and was thinking that i could put the 2 first lines of each function in the controller somewhere into a global variable but it seems im unable to do it ![]() i wanted it to look like this: Code: <?php anyone got an idea on how to solve it? Setting default variables in a controller - El Forum - 07-15-2007 [eluser]WeeJames[/eluser] Code: <?php Try that.. i assume its just the string 'user' that you're trying to access. You could also place the page_vars data into a variable in the same way. Code: <?php Read up on classes in php as this type of stuff isn't really CI related. Setting default variables in a controller - El Forum - 07-15-2007 [eluser]deineMudder[/eluser] works fine for the controller variable, ty alot. could u give me a hint how it works with the array too? i get some nasty errors now destroying my whole page ![]() Setting default variables in a controller - El Forum - 07-15-2007 [eluser]WeeJames[/eluser] Without seeing how you're using it i wouldn't be able to figure out whats going wrong ![]() Setting default variables in a controller - El Forum - 07-15-2007 [eluser]deineMudder[/eluser] mmhhh basically my "library" looks like this Code: class LibAdmin { and im using those variables in my functions of the controller and views and so on... Setting default variables in a controller - El Forum - 07-15-2007 [eluser]Glen Swinfield[/eluser] Just keep using $this-> for example: Code: function whatever{ Then access the values like this: Code: echo $this->page_vars['keyname']; //prints 'mystring'; It's all about $this when you're using objects - check the php manual for more info. Setting default variables in a controller - El Forum - 07-15-2007 [eluser]deineMudder[/eluser] okay ty and sorry again for asking such a question, i am not used to OO scripting. thx alot for ur answers guys Setting default variables in a controller - El Forum - 07-15-2007 [eluser]WeeJames[/eluser] If you're placing the page_vars array in $this->page_vars, the values should be accessible via $this->page_vars['view'] etc. If you're passing the whole array into your view.. e.g. $this->load->view('view', $this->page_vars) they'll be accessible via $heading and similar.. |