php—Smarty-缓存二(26)

WBOY
Release: 2016-06-13 12:19:27
Original
731 people have browsed it

php—Smarty-缓存2(26)

一个页面中,有些数据缓存,有些数据不缓存,就是局部缓存

l  $smarty->assign(“var”, “value”, true)

第三个参数:表示是否不缓存

l  {$var nocache=true}

在模板变量量后使用nocache参数

l  {nocache}{/nocache}

使用一对nocache标记,之间的所有内容不缓存

缓存文件:我们发现姓名被直接写到文件中,年龄每次都需要动态读取,实现局部缓存功能

尝试将name和age的值修改,注意页面上发生的变量,name不变,age改变

七、            单页面多缓存

http://localhost/news.php?id=100

查看id为100的新闻

访问后,会对这个模板生成一个缓存文件,缓存的是id为100的新闻

http://localhost/news.php?id=80

查看id为80的新闻

这时,看到的将是之前的缓存文件

l  $smarty->caching=true

开启缓存机制

l  $smarty->display(“tpl”, “cacheid”)

第二个参数表示缓存ID,就是某个缓存文件的唯一标准

代码:

我们分别使用这样的url来访问:

Demo07.php?id=10

Demo07.php?id=83

Demo07.php?id=96

然后,发现在缓存目录下,产生这样几个缓存文件:

文件名^之前的内容就是缓存ID,是缓存文件的唯一标识。

清除缓存文件时该如何操作?

$smarty->clearCache(‘demo07.html’);

这样写,表示将demo07模板的所有的缓存文件清除

$smarty->clearCache(‘demo07.html’,83)

这样写,表示将demo07模板对应的ID为83的缓存文件删除

八、 缓存集合

http://localhost/news.php?kid=10&page=8

表示想查看新闻分类id为10的新闻标题,并显示第8页的数据,该如何进行缓存?

l  $smarty->caching=true

开启缓存功能

l  $smarty->display(“tpl”, $id1.”|”.$id2)

设置缓存ID,并使用   |  进行连接,表示是一个缓存集合

代码:

 

 

运行以下url:

Deo08.php?kid=13&page=2

Deo08.php?kid=25&page=8

Deo08.php?kid=2&page=58

发现,在缓存目录下,产生这样几个缓存文件

其实,就是指将得到的所有参数用 | 连接,生成新的缓存文件

MVC中应用Smarty

一、MVC

1、M:模型

2、  V:视图

3、  C:控制器

就是需要用Smarty替换我们之前的View组件

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!