Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Shop high quality cheap prom dresses on Dresswe.co.uk

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store

Advertisement

�页多个缓存

在调用display()或者 fetch()的时候, 你�以设置�个页�有多个缓存。 当我们希望执行display('index.tpl')的时候, �以根���的情况�生���的缓存,并且�以�独区分, 那么就需�设置$cache_id为第二个�数�实现了。

Example 15.6. display()的�数作为$cache_id


<?php
require('Smarty.class.php');
$smarty = new Smarty;

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

$my_cache_id = $_GET['article_id'];

$smarty->display('index.tpl', $my_cache_id);
?>

     

上�,我们将$my_cache_id值作为$cache_id�数传递给 display()。 �个�独的$my_cache_id值,对应将会有�独的 index.tpl模�的缓存文件生�。 在这个例�里�,$cache_id是我们从URL中获得的article_id。

技术说明

当客户端(�览器)传递值到Smarty或任何的PHP程�时,务必谨慎。 虽然上�例�通过URL传递article_id显得比较方便,但�能会引起问题。 $cache_id值会用�建立文件目录的, 所以如果用户故�传递了�常大的值给article_id,或写个快速循环的脚本����机的article_id, 那么这很有�能引起一些�务器端的问题。 �记�,使用任何数���先检查。 在上�的例�中,或许article_id有10个字符的长度, 仅�以是字�数组的组�,而且还应该是存在于数�库内,那么,你就应该检查它�

确�用�一个$cache_id作为 isCached() 和 clearCache()的第二个�数。

Example 15.7. 给 isCached() 传递一个 cache_id


<?php
require('Smarty.class.php');
$smarty = new Smarty;

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

$my_cache_id = $_GET['article_id'];

if(!$smarty->isCached('index.tpl',$my_cache_id)) {
    // 没有缓存,这里将进行一些赋值�作
    $contents = get_database_contents();
    $smarty->assign($contents);
}

$smarty->display('index.tpl',$my_cache_id);
?>

     

�删除特定$cache_id的全部缓存, �时需�给clearCache() 传递null作为第一个�数。

Example 15.8. 删除特定$cache_id的缓存


<?php
require('Smarty.class.php');
$smarty = new Smarty;

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

// 删除$cache_id为"sports"的全部缓存
$smarty->clearCache(null,'sports');

$smarty->display('index.tpl','sports');
?>

     

按这�方�,你�以通过设置�一个$cache_id�把你的缓存“组织�起�。

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 10 plus 6? (Are you human?)

Advertisement