Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Configuration Smarty和配置_Configuration_Smarty - Fatal编程技术网

Configuration Smarty和配置

Configuration Smarty和配置,configuration,smarty,Configuration,Smarty,我有一些关于smarty优化的问题 1) 我刚刚使用smarty,我想知道,如果我想创建一个网站,我需要什么配置?我听说: $smarty->setTemplaceDir(..); $smarty->caching=1; 还有别的吗 2) 我经常看到: $smarty->display("index.tpl", $var); 第二个参数是什么? 同样的事情也发生在: $smarty->assign($var); $smarty->display("index.h

我有一些关于smarty优化的问题

1) 我刚刚使用smarty,我想知道,如果我想创建一个网站,我需要什么配置?我听说:

$smarty->setTemplaceDir(..);
$smarty->caching=1;
还有别的吗

2) 我经常看到:

$smarty->display("index.tpl", $var);
第二个参数是什么? 同样的事情也发生在:

$smarty->assign($var);
$smarty->display("index.html");
第二个参数$var似乎是为了实现最佳缓存优化,不是吗


提前感谢

所有这些都记录在。要设置您的需求,我建议您阅读以下方法:

  • setCaching
  • setCacheLifetime
  • setTemplateDir
  • setCacheDir
  • setCompileDir
  • addPluginsDir
同样有趣的还有
loadFilter('output','trimwhitespace')
escape\uhtml
。display的第二个参数是cache_id。当您想要为一个模板或模板堆栈存储多个缓存时,它很有用。例如,如果显示一个用户配置文件页面,并且缓存id设置为用户唯一标识符(用户id或其他),则smarty将为同一模板的每个用户创建一个缓存文件。这也可以通过
nocache
sections/modifiers解决。在我的结论中,当脚本执行需要很长时间而没有缓存时,最好使用cache_id。您也可以设置默认的缓存id。只需
$smartyobject->cache\u id=*somevalue*
。当您与
isCached
结合使用时,这将非常有用,因为此方法也接受缓存id

范例

<?php
$smarty = new Smarty;

//setup directories here...

$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
$smarty->setCacheLifetime(-1);

$userid = $_GET['userid'];
$smarty->cache_id = (string)$userid;

if(!$smarty->isCached('profile.tpl'))
    $smarty->assign('userData','some data');

$smarty->display('profile.tpl');
?>