Connecting Tech Pros Worldwide Forums | Help | Site Map

Setting relative path in class

chathura86's Avatar
Member
 
Join Date: May 2007
Location: Homagama, Sri Lanka
Posts: 92
#1: Jul 6 '08
i have created some php classes in deferent folders which requires each other
i have given relative paths relative to those files

i used require_once()

but when i use those class in a file outside the class folder i get a error
message stating that the path is incorrect

i seems like path is setting relative to the page im using those classes not relative
to the class which is requiring it.

please help me

thank you

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#2: Jul 6 '08

re: Setting relative path in class


you can use './' to go to the directory in which the inital include started.
chathura86's Avatar
Member
 
Join Date: May 2007
Location: Homagama, Sri Lanka
Posts: 92
#3: Jul 6 '08

re: Setting relative path in class


is there any way to specify the root folder

so i can generate the relative paths from the root
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#4: Jul 6 '08

re: Setting relative path in class


Heya, Chathura.

Try something like this:

Expand|Select|Wrap|Line Numbers
  1. require_once "{$_SERVER['DOCUMENT_ROOT']}/path/to/include/file.php";
  2.  
chathura86's Avatar
Member
 
Join Date: May 2007
Location: Homagama, Sri Lanka
Posts: 92
#5: Jul 12 '08

re: Setting relative path in class


it works

thank you very much

chathura bamunusinghe
Reply