Date: 07/05/00
- Next message: Luca - De Whiskey's - De Vitis: "[phplib-dev] bug in php-lib/php/ct_pgsql.inc"
- Previous message: Ignatius Teo: "[phplib-dev] Re: [phplib] Chat client in PHP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Folks,
This issue (see below) seems to have spun around the list a few times.
Here's a patch:
--- php/template.inc Wed Jun 28 17:47:59 2000
+++ ../../saltfire/zai/html/php/template.inc Wed Jun 28 17:48:48 2000
@@ -82,11 +82,13 @@
$this->halt("set_file: For handle $handle filename is empty.");
return false;
}
- $this->file[$handle] = $this->filename($filename);
+// $this->file[$handle] = $this->filename($filename);
+ $this->file[$handle] = $filename;
} else {
reset($handle);
while(list($h, $f) = each($handle)) {
- $this->file[$h] = $this->filename($f);
+// $this->file[$h] = $this->filename($f);
+ $this->file[$h] = $f;
}
}
}
The basic problem is that filename() gets called twice so relative paths get
prepended to the filename twice.
Edd has proposed a different approach to fixing the problem, i.e. making the
filename() method a little more careful about when it prepends the path.
Either approach will probably work fine but one or the other should probably
be applied.
Regards,
Toby
> Hi all,
>
> I'm new to this list (and PHP-LIB) so I apologise if this has been
> covered before. I couldn't see anything relevant in the archive.
>
> I've been playing with the Template class in PHP-LIB for a web app I've
> been working on and discovered that setting a template directory
> relative to the (web site's) document root, rather than an absolute
> filesystem path caused problems. This was undesirable as I don't want to
> have to change the code whenever I move the app to a different platform.
>
> e.g.
>
> 1. $tpl = new Template("templates","keep");
> 2. $tpl->set_file(array("main" => "main.tpl", // contains {HEADER}
> "header" => "header.tpl")); // contains
> {NAVIGATION}
> 3. $tpl->set_var(array("NAVIGATION" => "<b>navigation goes here</b>"));
> 4. $tpl->parse("HEADER","header");
> 5. $tpl->parse("global", array("header", "main"));
> 6. $tpl->p("global");
>
> would throw an error (filename: file templates/templates/header.tpl does
> not exist) on line 4. However, changing the root on line 1 to
> "/www/site1/htdocs/templates" would work fine... until I moved the app
> off our development server that is.
>
> This was caused by the filename() method prepending $this->root to any
> filename not starting with a '/'. Changing the if statement at the start
> of filename() to check for the slash _and_also_ check if the filename
> starts with $this->root (see below) solved my problem. (I guess you
> could just remove the slash check as the root check essentially makes it
> redundant)
>
> if ((substr($filename, 0, 1) != "/") &&
> (substr($filename, 0, strlen($this->root)) != $this->root)) {
>
> After all that I guess my question is, was this the right thing to do?
> Or is there a reason that filename only accepts absolute filenames? I
> look forward to your response.
>
> Cheers,
> Edd
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected>
For additional commands, e-mail: phplib-dev-help <email protected>
- Next message: Luca - De Whiskey's - De Vitis: "[phplib-dev] bug in php-lib/php/ct_pgsql.inc"
- Previous message: Ignatius Teo: "[phplib-dev] Re: [phplib] Chat client in PHP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

