Re: best way to set up an include path for a multi-level project?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 16 Mar 2010, John Black wrote:

> On 03/16/2010 06:57 PM, Robert P. J. Day wrote:
> >    i have a project (let's call it "proj") which lives in the "proj"
> > directory and which contains several subdirs, some of which might
> > contain their own subdirs and so on.  some of those subdirs might
> > contain utility classes that i want to include or require elsewhere,
> > so i want to be able to just:
> >    require 'util.php';
> > and have the PHP include path "do the right thing."  right now, it's
> > ugly, as in, having PHP files that do:
> >    require '../../proj/util.php';
> > meaning every single file that wants to include another proj-related
> > file has to know its relative position in the proj hierarchy.   barf.
>
> I used to use auto detecting absolute paths but switched to relative
> paths when a client decided to switch his hosting company, I *think*
> it was GoDaddy. They required relative paths when using the shared
> SSL server or the browser would throw errors.
>
> It is really not bad as long a you keep your directory structure
> consistent. I have never received a bug report because of an include
> path issue. It also does not matter where the root directory of the
> app is located since everything is relative anyway. There is also no
> need for the user to configure anything because of the relative
> paths.
>
> So I just set $include = './include/abc/def/' at the top of the
> executing php page and use it further down. You make $include a
> global or simply pass $include to functions or classes when they
> need to include files. I use the later approach.
>
> As I said I never had a problem with it, it just requires
> consistency.

  i'm not entirely sure what you're suggesting here, but i don't think
it will work for me as one of the things i want to do is set up a
"test" directory, inside which i might have subdirectories with more
test routines, so i can't guarantee *anyone's* position relative to
the top of the "proj" directory.

  i might even want to write PHP scripts and place them quite some
distance from the "proj" directory but still want to include utility
scripts from the "proj" directory.  based on how i've done this with
shell and makefile-based projects in the past, the easiest solution
seemed to be to simply demand that users set a single environment
variable identifying the location of the "proj" directory, and base
everything off of that by extending the include path.  at that point,
everything falls into place and all include/require references work
relative to the top of the "proj" tree.

  i think that's the direction i'm going to go, unless someone has a
compelling reason not to.  thanks.

rday
--

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

            Linux Consulting, Training and Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday
========================================================================

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux