Page 1 of 1
Newbie Question: Creating Objects
Posted: Fri Jun 28, 2002 9:48 am
by seem
Hello Everyone,
for a web-based computer managment application I've tried to use a file-structur similar to this:
/php/database ------------ DbHosts.php ------------- getHostsByName ($hostname)
\ \------------ getHostByIpAdress ($ip)
\---- Hosts.php ------ setHostname($hostname)
\----- getHostname()
How can I set a classpath or something similar to mark the location of all classes. If I am in /php/database/DbHosts.php and I want to get an instance from /php/Hosts.php I have now idea how I can handle this. (something like $hosts = new ../Hosts

)
Thanks in advance
Andy
Posted: Fri Jun 28, 2002 11:05 am
by twigletmac
Nope, you include each of the class files that you want to use.
Code: Select all
include_once 'class1.php';
include_once '../class2.php';
Then you can call new instances of the classes defined in those files:
If you use include_once() it solves problems where class files are included multiple times because they're included in one file and also included in a file that that page includes...
Mac
Posted: Mon Jul 01, 2002 3:04 am
by seem
Thank you for your help, but I get the following errors:
Warning: Unable to access ../database/DbHost.php in /usr/local/httpd/htdocs/cat/php/rendering/searchHostResult.php on line 3
Warning: Failed opening '../database/DbHost.php' for inclusion (include_path='') in /usr/local/httpd/htdocs/cat/php/rendering/searchHostResult.php on line 3
Fatal error: Cannot instantiate non-existent class: dbhost in /usr/local/httpd/htdocs/cat/php/rendering/searchHostResult.php on line 5
If I switch the safe mode off The first Warning disappears. I gues the following: The safe mode has prevented searchHostResult.php from accessing another directory. After turning the safe mode off it was possible to access ../database/DbHost.php but it was not possible to open this file.
The webserver has r-x - rights for accessing the files.
Is there any other option I have to set for accessing this php-files?
Include files
Posted: Mon Jul 01, 2002 8:18 am
by BDKR
Hola mi amigo,
Where is the file "DbHost.php" in relation to "searchHostResult.php"? What is the code you are using for your include statement? Is it something like
Code: Select all
include_once ("../database/DbHost.php");
Have you taken a look at the manual and read the section regarding "include_path"s? Also check what your $DOCUMENT_ROOT or $_SERVER[DOCUMENT_ROOT] var is set to.
Later on,
BDKR (TRC)
Posted: Mon Jul 01, 2002 8:30 am
by seem
Hello,
the warnings are caused by a stupid failure of me. searchHostsResult is included by index.php, which is stored in another folder. My include was in relation from searchHostResult to host.php but after changing it to the relation from index.php to hosts.php it worked fine.
Thanks for zou help
