Re: [SMARTY] templates_c
| From: | messju mohr | Date: | Tue, 24 Jun 2003 12:59:21 +0000 |
| Subject: | Re: [SMARTY] templates_c | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-9767@lists.php.net to get a copy of this message | ||
On Tue, Jun 24, 2003 at 02:05:11PM +0200, Wilhelm Kutting wrote:
> hi,
> i do not know where is the best way to config the path of templates_c
> and the cache dir on a linux system.
(i don't know if i understand your question 100%, but anyway:)
there are two common ways:
$smarty = new Smarty();
$smarty->compile_dir = ...
or
class My_Smarty extends Smarty {
function My_Smarty() {
$this->Smarty();
$this->compile_dir = ...
}
}
$smarty = new My_Smarty;
i normally use the former in a config.php that is included by all
php-files that are exposed to the web.
as a starter:
the vague directory-layout of BASEDIR:
/config.php
/html/ <- this is the servers document-root
/html/index.php
/html/images/
/html/...
/lib/smarty/ <-- smarty's libs/directory
/lib/smarty/Smarty.class.php
/lib/smarty/plugins/... <-- smartys distribution's plugins
/lib/... <- other third party stuff
/templates/ <- guess :)
/php/ <- other php-stuff, that can be invisible via http
/php/plugins/ <- application-specific plugins
/phptmp/ <- stuff where the webserver wants to write into
/phptmp/templates_c/
/phptmp/cache/
/phptmp/sessions/
...
in config.php:
<?php
define('BASEDIR', realpath(dirname(__FILE__)).'/');
define('SMARTY_DIR', BASEDIR.'lib/smarty/');
# (use
# define('SMARTY_DIR', '/usr/local/lib/smarty/');
# or the like if you want to use a shared smarty)
require_once(SMARTY_DIR.'Smarty.class.php');
$smarty =& new Smarty;
$smarty->use_sub_dirs = false;
$smarty->plugins_dir = array(BASEDIR.'php/plugins'
, SMARTY_DIR.'plugins'
);
$smarty->template_dir = BASEDIR.'templates';
$smarty->compile_dir = BASEDIR.'phptmp/templates_c';
$smarty->cache_dir = BASEDIR.'phptmp/cache';
...
?>
and in html/index.php:
<?php
require_once('../config.php');
$smarty->display('foo.tpl');
?>
the point is, this way, i don't have to hard-code a single path in the
php-files. i can even duplicate the whole tree and maintain different
versions without having to touch config.php everytime.
and i didn't have "problems writing /%%9..." for ages :)
the realpath(..) stuff can be a little performance hit in comparason
to a hard-coded path here. but i'm willing to take this for the
convinience i get by it.
sometimges i do realpath(dirname(.. only at the development-version(s)
and use a hard-coded path in the production-version. but i think you
must have a very attractive site if you need this little
difference. :)
> could it be that i ran into trouble when i put the path of templates_c
> for a lot of websites inside the same dir?
rule of thumb: if they have different template-dirs, they need
different template_c-dirs.
> and is there any garbage collector what kills the old template_c files.
nope.
greetings
messju