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]

 



> let me emphasize that the layout of the entire "proj" directory will
> be consistent across all users and all machines since it will
> represent a single SVN checkout, so that's not an issue.  of course,
> anyone will be free to check it out anywhere they want but once they
> do, its structure will be the same across all checkouts.

The problem of an easy include path also came up in our project. The
solution was to create a Bootstrap class, that sets the include path as
follows:


  private function __construct() {
    // Set the include path, where to look for included files.
    // This is important so as to make pointing to the included files
much easier,
    // and to avoid tortuous path references.
    $this->bibledit_root_folder = dirname (dirname(__FILE__));
    $include_path = get_include_path () . ":" .
$this->bibledit_root_folder;
    set_include_path ($include_path);
    ini_set('include_path', $include_path); 
  } 

The central issue in the above is to use the __FILE__ variable as the
starting point for the include path. Since the bootstrap.php is in a
known location in the directory tree, we can always deduce a known
include path from that.

After that, each php file in each directory was set to include this
bootstrap.php, in various forms, depending on where this php file was
located in the directory tree:

require_once ("../bootstrap/bootstrap.php");

or:

require_once ("../../bootstrap/bootstrap.php");

or

require_once ("bootstrap/bootstrap.php");

That way the include path got set bootstrap.php. It works well.

Teus.


-- 
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