smarty缓存文件里是php,php-smarty模版引擎中的缓存应用
php-smarty模版引擎中的缓存应用
同学们在学习的时候一定要保持足够耐心,才能把知识学好。以下百分网小编整理的php smarty模版引擎中的缓存应用实例代码的介绍,希望对大家有所帮助,更多信息请关注应届毕业生网!
1,Smarty缓存的配置:
$smarty->cache-dir="目录名"; //创建缓存目录名
$smarty->caching=true; //开启缓存,为false的时候缓存无效
$smarty->cache_lifetime=60; //缓存时间,单位是秒
2,Smarty缓存的使用与清除
$marty->display("cache.tpl",cache_id); //创建带ID的缓存
$marty->clear_all_cache(); //清楚所有缓存
$marty->clear_cache("index.php"); //清楚index.php中的缓存
$marty->clear_cache("index.php',cache_id); //清楚index.php中指定ID的缓存
3,Smarty的局部缓存
第一个: insert_函数默认是不缓存,这个属性是不能修改
使用方法:例子
index.php中,
function insert_get_time(){
return date("Y-m-d H:m:s");
}
index.html中,
{insert name="get_time"}
第二个: smarty_block
定义一个block:smarty_block_name($params,$content, &$smarty){return $content;} //name表示区域名
注册block:$smarty->register_block('name', 'smarty_block_name', false); //第三参数false表示该区域不被缓存
模板写法:{name}内容{/name}
写成block插件:
1)定义一件插件函数:block.cacheless.php,放在smarty的plugins目录
block.cacheless.php的`内容如下:
function smarty_block_cacheless($param, $content, &$smarty) {
return $content;
}
?>
2) 编写程序及模板
示例程序:testCacheLess.php
代码如下:
include('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching=true;
$smarty->cache_lifetime = 6;
$smarty->display('cache.tpl');
?>
所用的模板:cache.tpl
已经缓存的:{$smarty.now}
{cacheless}
没有缓存的:{$smarty.now}
{/cacheless}
4自定义缓存
设置cache_handler_func使用自定义的函数处理缓存
如:
$smarty->cache_handler_func = "myCache";
function myCache($action, &$smarty_obj, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null){
}
该函数的一般是根椐$action来判断缓存当前操作:
switch($action){
case "read"://读取缓存内容
case "write"://写入缓存
case "clear"://清空
}
一般使用md5($tpl_file.$cache_id.$compile_id)作为唯一的cache_id
如果需要,可使用gzcompress和gzuncompress来压缩和解压
smarty缓存文件里是php,php-smarty模版引擎中的缓存应用相关推荐
- Symfony2模版引擎使用说明手册
一.基本使用 {{ demo }}输出一个demo变量; {% func %}通常是包含一个twig函数例如 for; 举个for循环的例子: {% for i in 0..10 %} <em& ...
- php smarty 模版引擎,php模板引擎Smarty入门 - 小俊学习网
如果要实现前端模板和后台逻辑业务处理相分离,MVC的思想开发网站的话,可使用模板引擎来完成.来学习php模板引擎Smarty,它分开了逻辑程序和外在的内容,提供了一种易于管理的方法. 1. 什么是模板 ...
- php smart模板,PHP 模版引擎Smarty介绍
用PHP实现MVC开发模式的逻辑层和表示层有多种模板引擎可供选择,但是官方引擎SMARTY诞生后,选择就有了变化.它的理念和实现都是相当前卫的.本文主要讨论SMARTY之于其他模板引擎的不同特点,简要 ...
- php smarty 忽略,PHP详细彻底学习Smarty
PHP详细彻底学习Smarty 更新时间:2008年03月27日 22:56:17 作者: Smarty是一个php模板引擎,它分开了逻辑程序和外在的内容,提供了一种易于管理的方法. Smarty ...
- smarty.class.php,自定义min版smarty模板引擎MinSmarty.class.php文件及用法
本文实例讲述了自定义的min版smarty模板引擎MinSmarty.class.php文件.分享给大家供大家参考,具体如下: 一.smarty的优点 smarty是一个使用PHP写出来的模板引擎,是 ...
- 学习smarty手记一,如何配置smarty
学习PHPSMARTY 下载 先在smarty.php.net下载最新smarty 一般做法: 1解压smarty. 2 将libs文件夹放在你的WEB目录下,我是放在smarty下的,目录情况如下: ...
- smarty php5.5,thinkphp5.1使用Smarty模板引擎
Thinkphp5.1使用Smarty模板引擎 习惯了使用smarty的小伙伴,如果不想修改已有的模板代码,可以直接使用composer安装Smarty库,修改模板配置文件就可以直接使用smarty模 ...
- smarty课程---最最最简单的smarty例子
smarty课程---最最最简单的smarty例子 一.总结 一句话总结:其实所有的模板引擎的工作原理是差不多的,无非就是在php程序里面用正则匹配将模板里面的标签替换为php代码从而将两者混合为一个 ...
- php smarty框架案例,php封装的smarty类案例
这篇文章主要介绍了php封装的smarty类,针对Smarty的基本操作技巧进行了封装整理,具有一定参考借鉴价值,需要的朋友可以参考下 具体如下: /** * Project: Smarty: the ...
最新文章
- UC浏览器代理流量解密
- java继承详解加练习题
- Exchange 2010和Exchange 2016共存部署-10:配置多域名证书
- linux 进程间 close-on-exec 机制 简介
- 将 Net 项目升级 Core项目经验:(一)迁移Net项目为Net Core\Standard项目
- 小程序禁止左右拖动_网课视频快进小技巧
- Bailian2885 计算反序数【进制】
- eclipse(mac)启动配置-设置jdk路径
- ORM定制的几点注意事项
- linux一个数据页多少,复习——Linux
- 创建 Agg 静态链接库
- 用代码生成PDF文档的方法
- oracle 数据库 去重查询
- WX系列无线漫游的配置
- YY直播产品体验报告
- MySql重装出错, Staring the server出错,日志3306 with user root with no password...
- cpython cython_Cython笔记
- 计算机操做系统(十二):进程同步和互斥
- 服务器上MySQL数据库密码忘了
- 16-kubernetes集群中ceph集群使用
热门文章
- Python中使用xpath获取select option的每一行的text和value
- hive分桶表join_Hive知识梳理
- ajax+++fc,06. 实做AJAX(SEFC)
- vue的v-html使用
- MySQL 2006-MySQLserver has gone away
- ES启动错误 ERROR: the system property [es.path.conf] must be set
- maven clean警告:The requested profile “pom.xml“ could not be activated because it does not exist
- java在循环中删除数组元素,在循环Perl中删除数组中的元素
- FastDFS安装脚本
- Spring boot 第一章 Spring发展历史