Page 1 of 1

Call Function in Separate File

Posted: Wed Nov 26, 2008 4:27 pm
by blodder24
I have a function, merge(), in admin.php which is defined by: class admin extends catalog. (catalog is a file with more functions) When I try to call this function from index.php by using $admin->merge I get the error: Call to a member function merge() on a non-object.

Any idea what's going wrong?

Thanks

Re: Call Function in Separate File

Posted: Wed Nov 26, 2008 4:29 pm
by Mark Baker
have you instantiated an object of class admin?

Re: Call Function in Separate File

Posted: Wed Nov 26, 2008 4:37 pm
by blodder24
Thanks! That solved one problem, but created another.
How do you initiate: $this->core->db->run() inside the function merge()? I'm getting the same error when I try to run this function.

Re: Call Function in Separate File

Posted: Wed Nov 26, 2008 4:44 pm
by Mark Baker
blodder24 wrote:How do you initiate: $this->core->db->run() inside the function merge()? I'm getting the same error when I try to run this function.
Assuming you've instantiated an object of your database class, you pass that object as a parameter into the call to instantiate your admin class, and stick it in one of your admin class attributes.
That way, it's available to all the methods in your admin class

Re: Call Function in Separate File

Posted: Wed Nov 26, 2008 4:47 pm
by blodder24
Thanks for your help!