hi guys. i am writing a class for registering data and i am having a problem calling functions and vars from other classes.

here's a class diagram of where everything is called-

[IMG]http://img376.imageshack.us/img376/19/classesdm8.png[/IMG]


i am in forms, and i am having difficulty getting vars from site, using my functions in postgredb and vars from user.

i can get data from form easily.

$this->var

but when i try getting data from site i get an fatal saying site is not a member of form, ($this->site->var) so, how do i call data from a parent class?


solved
solved it- used a public $p; then set $form->p = $this, and then when calling parent date - $this->p->var...

you can send a reference to the parent class through the constructor and set it as a local var in the class.

example:

class test {
var $var;
function __construct() {
$this->var = 'something';
}
function testing() {
echo 'This is the parent function';
}
}

class test2 {
var par;
var var2;
function __construct( &$par ) {
$this->par = $par;
}
}

$test = new test();
$test2 = new test2( $test );

$test2->par->testing() //will echo 'this is the parent class';

thats one way to do it. there are more.

if the thread is solved, please mark it as so. This way I don't waste anymore time replying to something that you already figured out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.