Re: [SMARTY] Smarty and directory layout
| From: | Robert Amos | Date: | Fri, 31 May 2002 01:27:11 +0000 |
| Subject: | Re: [SMARTY] Smarty and directory layout | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-4474@lists.php.net to get a copy of this message | ||
the $smarty->template_dir variables have nothing to do with the SMARTY_DIR
constant. unless you change them, they point to a directory that¹s relative
to the CURRENT WORKING DIRECTORY.
So if you have your script in $HOME/project/index.php then it will look for
$HOME/project/templates, $HOME/project/templates_c, etc. it also searches
the include path for the directories
you can specify absolute paths to the template directories if you want, just
use
$smarty = new Smarty;
$smarty->template_dir = "/absolute/path/to/templates";
$smarty->compile_dir = "/absolute/path/to/templates_c";
hope that helps.
-bok
On 31/5/02 10:00 AM, Michael Stolovitzsky banged a keyboard and produced the
following weird but readable email:
> Hello, everyone,
>
> I am using Smarty in my PHP framework. Smarty is a brilliant work and I like
> it very much.
>
> The problem however is that Smarty is written in assumption that the directory
> layout is fixed. Since I wanted to separate the framework root directory from
> the web project's root directory, I moved directories around. Namely, I
> wanted class files in one location, templates and caches in another location,
> plugins in another.
>
> This is where Smarty gave me hell. Things broke immediately as soon as I
> separated the directories and tried to hack around Smarty source to
> understand the logic by which Smarty uses directories.
>
> SMARTY_DIR defines where Smarty root is located. The code implies that A)
> Smarty files (compiler and config classes) sit at SMARTY_DIR. Also, Smarty
> class has variables template_dir, config_dir etc that are B) supposed to be
> used when calculating absolute paths as relatives to SMARTY_DIR.
>
> However, in reality most of the code that makes use of Smarty->*_dir doesn't
> do any real path calculation. Eg where it's supposed to do
>
> some_func(SMARTY_DIR.$this->relative_dir->$file_name);
>
> it does
>
> some_func($this->relative_dir->$file_name);
>
> The very bad thing about this bug is that it doesn't trigger if everything
> resides in a predefined layout, basically because inside some_func there's
> code like
>
> function some_func($target_file) {
> fopen($target_file,...
> }
>
> which will work perfect on $target_file because $target_file would be
> considered relative to the current directory (which is same as SMARTY_DIR in
> an ideal condition) unless the path is absolute (and it isn't because most of
> Smarty code forgets to add SMARTY_DIR.
>
> Indeed if you want to place Smarty root somewhere other than where your
> invoking code's current directory is, things will break.
>
> The obvious logical solution to this would be to make the code calculate the
> paths everywhere as it should, but then it presents another problem: you
> can't effectively place anything above the Smarty root directory. My
> framework root is $HOME/framework, smarty is located in
> $HOME/framework/lib/smarty and my web project is $HOME/project, meaning that
> if I fix Smarty I won't be ever able to reach something above
> $HOME/framework/lib/smarty.
>
> Then you browse a little more around the source and you encounter trusted
> directories and whatnot. It's 4 a.m.
>
> Anyone has ideas, suggestions? :-)
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>