How to delete my avatar?
[SMARTY] Smarty and directory layout
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > PHP web-programming > [SMARTY] Smarty and directory layout 31 May 2002 09:27:23

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

[SMARTY] Smarty and directory layout

Michael Stolovitzsky 31 May 2002 09:27:23
 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_DI­R.$this->relative_di­r->$file_name);

it does

some_func($this->re­lative_dir->$file_na­me);

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_f­ile) {
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


Add comment
Robert Amos 31 May 2002 04:27:11 permanent link ]
 the $smarty->template_d­ir 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/templ­ates, $HOME/project/templ­ates_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_d­ir = "/absolute/path/to/­templates";
$smarty->compile_di­r = "/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_DI­R.$this->relative_di­r->$file_name);>
it does>
some_func($this->re­lative_dir->$file_na­me);>
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_f­ile) {> 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>


--
Smarty General Mailing List (http://smarty.php.­net/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Bertrand DUNOGIER 31 May 2002 09:27:23 permanent link ]
 
This is where Smarty gave me hell. Things broke immediately asMS> soon as I separated the directories and tried to hack aroundMS> Smarty source to understand the logic by which Smarty usesMS> directories.
I'm not sure I understand your problem perfectly, but it sounds pretty
trivial to me: all you want is to be able to have Smarty, templates,
compiled templates, cache and scripts anywhere on the server, right ?

It was what i have. For a particular website, I've got a
/home/www/sites/sit­ename/ directory. In this directory are several
sub-directories:
html (the document root)
templates
phpdata/templates_c­
phpdata/cache
...
(include_path is used so that there is nothing to change when you move
these directories)

Smarty is located in /usr/local/lib/php/­smarty-templates/, and is used
from that location by several sites.

At the beginning of my auto_prepend file, i create my Smarty instance,
then set the class parameters i need to change:

include 'Smarty.class.php';­
$tpl = new Smarty;
$tpl->template_dir = $smarty_templates;
$tpl->compile_dir = $smarty_templates_c­;
$tpl->cache_dir = $smarty_cache;

the $smarty_* variables were set in my config.php file.

Smarty's files location does not change anything, as long as
include_path is used...

Hope it helps.

Bertrand



--
Smarty General Mailing List (http://smarty.php.­net/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > PHP web-programming > [SMARTY] Smarty and directory layout 31 May 2002 09:27:23

see also:
MySQL BLOB fields and large binary data
Conformance of PostgreSQL to ANSI/ISO…
пройди тесты:
see also:
E-Cracker 9.0 ( Hotmail, Gmail, yahoo…
Documentum Training needed
Quantum

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .