Wally Kolcz
Wally Kolcz

Reputation: 1664

Setting an absolute include_path in PHP

I have a number of classes (Managers and Data) that have include_once's. Seems that when I include a data class into a manager, they work fine together...but when I include the manager class in my view to get the data, it's broken. I assume due to the view actually adding the manage to itself which makes the path to the data incorrect since the view is up 3 directories from root /adoptions/apps/add/ and the manager and data classes are 4 directories from the root. Is that correct?

Since I am new to PHP I noticed that / takes me further back than just the web root. I am running apache on a windows machine and the path to the htdoc is actually

c:/Program Files(x86)/Zend/Apache2/htdocs/mywebsite 

(if that helps at all). I would like to just have all my includes be something like

 include_once('/com/mywebsite/data/people/People.class.php';

Thanks!

Upvotes: 0

Views: 179

Answers (1)

Liam Bailey
Liam Bailey

Reputation: 5905

You need to set the include_path property in the php.ini file of your installation. Clear the existing entries if you wish, or add a semi-colon and then c:/Program Files(x86)/Zend/Apache2/htdocs

Then all paths will be relative to that, so you can just go include("/mywebsite/data/people/People.class.php");

Alternatively you can do this in .htaccess file:

php_value include_path ".;c:/Program Files(x86)/Zend/Apache2/htdocs"

or one of these two methods in your php itself:

ini_set("include_path",".;c:/Program Files(x86)/Zend/Apache2/htdocs");

Or set_include_path(".;c:/Program Files(x86)/Zend/Apache2/htdocs");

Upvotes: 2

Related Questions