CodeIgniter Forums
How can I set variables for an entire constructor? - 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: How can I set variables for an entire constructor? (/showthread.php?tid=2939)



How can I set variables for an entire constructor? - El Forum - 08-31-2007

[eluser]Nicholas Helke[/eluser]
Hi!

I have a post constructor which handles all posts to the database. There are three arrays that I want to be able to access in all the different functions of the constructor.

Set these in the class class constructor doesn't let me access them from the functions using just their name. If there is a way, I don't know it.

Thanks,

Nicholas


How can I set variables for an entire constructor? - El Forum - 08-31-2007

[eluser]Crafter[/eluser]
Assign the values to variables with class scope
Code:
class Category extends Controller {

var $var1;

function one() {
  $this->var1 = 'one';
}

function two() {
  $this->var1 = 'two';
}

}



How can I set variables for an entire constructor? - El Forum - 08-31-2007

[eluser]Nicholas Helke[/eluser]
Thank you very much!

Problem solved.