Smarty-2.6.12 FAQ 有感
2006-02-12  作者:阿毛  同分类文章
description:

Q: How can I be sure to get the best performance from Smarty?
A: Be sure you set $compile_check=false
问题:我怎么确认smarty处于最优化性能。回答:保证你设置$compile_check=false
本文列出了compile_check的作用,利用建立不同的缓存来准备为fyblog index.php提供完整的cache

 每次调用PHP应用程序,Smarty 会试着查看自上次编译时间以来,当前模板是否被修改过.如果修改过了,她会重新编译那个模板.如果模板还没有被编译过,她将编译模板而不管编译检查如何设置.默认情况下编译检查这个变量设置为true.一旦一个应用程序投入产品中(模板将不会修改了),就不再需要编译检查这一步了.为了最大性能,确定将$compile_check设为"false".注意:如果设为了"false",虽然模板文件被修改,但你不会看到修改结果,因为模板没有得到重新编译.如果启动了缓存和编译检查,一旦有关模板文件或配置文件被更新,缓存文件将会重建.

Q: How do I generate different cache files per template based on arguments
   passed to the page?
A: Use your $REQUEST_URI as the cache_id when fetching the page:

   global $REQUEST_URI; // if not already present
   $smarty->display('index.tpl',$REQUEST_URI);

   This will create a separate cache file for each unique URL when you call
   index.tpl. See the documentation for display() and fetch()
通过给display()第二个参数为$REQUEST_URI 来为不同的动态页面建立cache
技术提示:要注意从客户端(web浏览器)传值到Smarty(或任何PHP应用程序)的过程。尽管上面的例子用
article_id从URL传值看起来很方便,却可能有糟糕的后果[安全问题]。cache_id被用来在文件系统里创建
目录,如果用户想为article_id赋一个很大的值,或写一些代码来快速发送随机的article_ids,就有可能会
使服务器出现问题。

怎么在非缓存模板里面包换,缓存模板 
Q: How do I include cached template(s) within a non-cached template?
A: One way to do it:

   $smarty->caching = true;
   $tpl1 = $smarty->fetch("internal1.tpl");
   $tpl2 = $smarty->fetch("internal2.tpl");
   $tpl3 = $smarty->fetch("internal3.tpl");

   $smarty->assign("tpl1_contents",$tpl1);
   $smarty->assign("tpl2_contents",$tpl2);
   $smarty->assign("tpl3_contents",$tpl3);

   $smarty->caching = false;
   $smarty->display('index.tpl');

   index.tpl
   ---------

   <table>
           <tr>
                   <td>{$tpl1_contents}</td>
                   <td>{$tpl2_contents}</td>
                   <td>{$tpl3_contents}</td>
           </tr>
   </table>

 


   Another approach:

   You could write a custom insert function to fetch your internal
   templates:

   <table>
           <tr>
                   <td>{insert name=fetch_tpl tpl="internal1.tpl"}</td>
                   <td>{insert name=fetch_tpl tpl="internal2.tpl"}</td>
                   <td>{insert name=fetch_tpl tpl="internal3.tpl"}</td>
           </tr>
   </table>



相关
MolyX BOARD 2.5.0 多语言标准版 发布
在windows下安装apache,php,mysql
无限级分类
用php模拟post来提交数据
统计在线时间
用PHP处理多个同名复选框
读取NFO信息的php代码。
面向对象程序设计怎么设计对象
email地址php检测
免费 pdf 库类 library