jordan_windebank — 2013-12-27T05:34:28-05:00 — #1
Hi all, long time no visit however now that I've dusted off the old coding skills I need some help please.
I am having a world of trouble getting my head around PHP relative paths. Below is my folder structure:
In my index.php if I want to include a class I am using:
Which is not elegant, but it's working.
My trouble is in trying to reference the Doctrine DBAL library. I have tried the following and nothing seems to work!
I have tried setting the include_path as follows:
$path = dirname(__FILE__).'\\..\\app\\lib';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
I know I am missing something fundamental here but I can't wrap my head around it. Really appreciate any pointers.
ralphm — 2013-12-27T07:29:55-05:00 — #2
If you are referencing it from index.php, the relative path would be
But absolute paths are more convenient, because they can be used from anywhere:
... although you may need to do it like this:
$_SERVER["DOCUMENT_ROOT"] . "/src/app/lib/Doctrine/DBAL/"
jordan_windebank — 2013-12-29T05:14:47-05:00 — #3
Thanks @ralph_m ; got it sorted.
ralphm — 2013-12-29T06:40:52-05:00 — #4
Cool. Glad to hear it.
starlion — 2013-12-29T07:26:40-05:00 — #5
Just be careful in recognizing which functions use the filesystem instead of the URL (or more specifically, serverRoot).
/sys means something ENTIRELY different when referencing the filesystem, which is why ralph suggests putting the SERVER DOC_ROOT variable in front of it; it'll make sure your absolute scripts don't go looking in the wrong places on *NIX filesystems.