Smarty and directory layout

From: Date: Fri, 31 May 2002 00:00:31 +0000
Subject: Smarty and directory layout
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4473@lists.php.net to get a copy of this message
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? :-)

« previous php.smarty.general (#4473) next »