Re: Includes in libraries

From: FLEB (soon.the.sp_at_mmers.and.evil.ones.will.bow-down-to.us)
Date: 12/04/03


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


Relevant Pages

  • Re: On More Time - TNT High Definition is NOT!
    ... This practice started with text only systems (no HTML). ... quote was with some prefix character per line. ... Most text email clients, and many rich text ones, can automatically include ... Usenet is still ASCII text based. ...
    (alt.tv.tech.hdtv)
  • Re: fake PC supplies
    ... >> The quote makes more sense when it's complete. ... For the love of money is the root of all evil ...
    (sci.electronics.design)
  • Re: bye-bye holly hack...
    ... As far as I can see, there is a difference between the DOM and CSS Recommendations regarding what constitutes the "root of the document tree". ... The Document interface represents the entire HTML or XML ...
    (comp.infosystems.www.authoring.stylesheets)
  • Re: BeautifulSoup bug when ">>>" found in attribute value
    ... I don't think I would quibble with what BeautifulSoup extracted from that ... The input isn't valid HTML so any output has to be guessing at what ... quote missing and the tag was terminated by the first '>'. ... IE) will often accept entities without the terminating semicolon, ...
    (comp.lang.python)
  • RE: Internet UTC
    ... Local lcQuote As String,; ... *-- Grab the quote from the Web page. ... *-- trailing HTML with the TRANSFORMAND VALfunctions. ...
    (microsoft.public.fox.programmer.exchange)