Re: Includes in libraries
From: FLEB (soon.the.sp_at_mmers.and.evil.ones.will.bow-down-to.us)
Date: 12/04/03
- Next message: Google Mike: "pg_query() and double quotes"
- Previous message: FLEB: "Re: how do I check if the referrer was used HTTP or HTTPS?"
- In reply to: Tim Tyler: "Includes in libraries"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 4 Dec 2003 14:22:34 -0500
Regarding this well-known quote, often attributed to Tim Tyler's famous
"Tue, 2 Dec 2003 14:58:07 GMT" speech:
> A fairly simple question:
>
> I have a library A which depends on library B and C.
>
> Currently I have:
>
> <?php
> include("A.inc.php");
> include("B.inc.php");
> include("C.inc.php");
> ?>
>
> ...in my HTML.
>
> This needs changing to:
>
> <?php
> include("../A.inc.php");
> include("../B.inc.php");
> include("../C.inc.php");
> ?>
>
> ...if I call it from deeper in the directory tree.
>
> I don't want lots of includes in my HTML. I want to write:
>
> <?php
> include("A.inc.php");
> ?>
>
> ...and to have the other includes in the "A.inc.php" file.
>
> However if I put:
>
> include("B.inc.php");
> include("C.inc.php");
>
> ...in the library, it doesn't fild the files when included using:
>
> <?php
> include("../A.inc.php");
> ?>
>
> ...in an HTML file some distance from the root.
>
> I don't want to wire absolute paths in.
>
> I *could* pass the "../" in as a method parameter - but that
> seems like a total mess.
>
> What is the best way to resolve this issue?
You could just drop a "definitions" script within your root path, and
include that from the included files:
<includes.inc.php> -----------------------------------------------
$_ROOT_INC_PATH_ = "/home2/bobdrilo/public_html/php-includes";
$_MYSQL_LIB_PATH_ = "$_ROOT_INC_PATH_/mysql/mysql-lib.php";
$_GRAPHICS_LIB_PATH_ = "$_ROOT_INC_PATH_/graphicslib/gfxlib.php";
$_TABLEGEN_LIB_PATH_ = "$_ROOT_INC_PATH_/tables/tables.php";
...
<includes.inc.php> -----------------------------------------------
then, call your includes with the variables:
<dostuff.php> ----------------------------------------------------
include("includes.inc.php"); // this is in the root includes path
include($_GRAPHICS_LIB_PATH_);
include($_MYSQL_LIB_PATH);
...
<dostuff.php> ----------------------------------------------------
-- -- Rudy Fleminger -- sp@mmers.and.evil.ones.will.bow-down-to.us (put "Hey!" in the Subject line for priority processing!) -- http://www.pixelsaredead.com
- Next message: Google Mike: "pg_query() and double quotes"
- Previous message: FLEB: "Re: how do I check if the referrer was used HTTP or HTTPS?"
- In reply to: Tim Tyler: "Includes in libraries"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|