smarty3-笔记
smarty3笔记
1、Samrty.class.php 的compile_dir 和template_dir类属性 是private的,setTemplateDir和setCompileDir类方法是public的,可以通过public的修改private的
class MySmarty extends Smarty{
public function __construct(){
parent::__construct();
}
$this->setTemplateDir();
$this->setCompileDir();
}
2、smarty既能取值也能赋值,{$smarty.name},{$smarty.name="bob"}
3、
$smarty->template_dir = ROOT . 'view/smarty/templeate'; $smarty->compile_dir = ROOT . 'view/smarty/compile'; $smarty->caching = true; $smarty->cache_lifetime = 3600; $smarty->cache_dir = ROOT . 'view/smarty/cache'; $smarty->setTemplateDir(ROOT . 'view/smarty/templeate'); $smarty->setCompileDir(ROOT . 'view/smarty/compile'); $smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT); $smarty->setCacheDir(ROOT . 'view/smarty/cache'); $smarty->setCacheLifetime(100);
$smarty->clearCache(); $smarty->clearAllCache();
4.smarty.class.php
4.1:DIRECTORY_SEPARATOR--php系统内置变量用于不同的操作系统显示不同的目录分隔符,在window里输出\
const DIR_SEP = DIRECTORY_SEPARATOR;// 路径分割 win下\ linux下/
private function __construct()
{
$this->_options = array(
'template_dir' => 'templates' . self::DIR_SEP, //模板文件所在目录
'cache_dir' => 'templates' . self::DIR_SEP . 'cache' . self::DIR_SEP, //缓存文件存放目录
);
}
42.:PATH_SEPARATOR-路径分隔符,在win下是;在linux下是:
5.缓存
5.1开启-缓存可以通过设置 $caching为:Smarty::CACHING_LIFETIME_CURRENT 或 Smarty::CACHING_LIFETIME_SAVED来开启。
$cache_lifetime默认是一小时,Smarty::CACHING_LIFETIME_SAVED可以让每个模板配置不同的缓存时间
6.局部不缓存
6.1模板区域不缓存{nocache}{$smarty.now|data_format}{/nocache}
6.2标签不缓存{$smarty.now|data_format nocache}
6.3变量不缓存$smarty->assign('data',time(),true);
6.4插件的不缓存
7.单页面多缓存
通过display或者fetch的第二个参数来设置根据不同$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);
?>
smarty3-笔记的更多相关文章
- Smarty3学习笔记
Smarty3 笔记 By 飞鸿影~ -- :: Smarty入门 1.什么是smarty? Smarty是采用php写的一个模版引擎,设计的目的是要将php代码与html代码分离, 使php程序员只 ...
- git-简单流程(学习笔记)
这是阅读廖雪峰的官方网站的笔记,用于自己以后回看 1.进入项目文件夹 初始化一个Git仓库,使用git init命令. 添加文件到Git仓库,分两步: 第一步,使用命令git add <file ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- SQL Server技术内幕笔记合集
SQL Server技术内幕笔记合集 发这一篇文章主要是方便大家找到我的笔记入口,方便大家o(∩_∩)o Microsoft SQL Server 6.5 技术内幕 笔记http://www.cnbl ...
- PHP-自定义模板-学习笔记
1. 开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2. 整体架构图 ...
- PHP-会员登录与注册例子解析-学习笔记
1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...
- NET Core-学习笔记(三)
这里将要和大家分享的是学习总结第三篇:首先感慨一下这周跟随netcore官网学习是遇到的一些问题: a.官网的英文版教程使用的部分nuget包和我当时安装的最新包版本不一致,所以没法按照教材上给出的列 ...
- springMVC学习笔记--知识点总结1
以下是学习springmvc框架时的笔记整理: 结果跳转方式 1.设置ModelAndView,根据view的名称,和视图渲染器跳转到指定的页面. 比如jsp的视图渲染器是如下配置的: <!-- ...
- 读书笔记汇总 - SQL必知必会(第4版)
本系列记录并分享学习SQL的过程,主要内容为SQL的基础概念及练习过程. 书目信息 中文名:<SQL必知必会(第4版)> 英文名:<Sams Teach Yourself SQL i ...
随机推荐
- 闭包 -> map / floatMap / filter / reduce 浅析
原创: 转载请注明出处 闭包是自包含的函数代码块,可以在代码中被传递和使用 闭包可以捕获和存储其所在上下文中任意常量和变量的引用.这就是所谓的闭合并包裹着这些常量和变量,俗称闭包.Swift 会为您管 ...
- iOS 开发之照片框架详解之二 —— PhotoKit 详解(上)
转载自:http://kayosite.com/ios-development-and-detail-of-photo-framework-part-two.html 一. 概况 本文接着 iOS 开 ...
- 用for while 成绩的有效输入
#include "stdio.h" void main() { int score,s; printf("请输入你的成绩:"); scanf("%d ...
- php实现echo json_encode正确显示汉字
<?php header('Content-type: text/html; charset=utf-8'); /* function showmessage($msg = '', $redir ...
- 善用log日志
#-*- coding:utf-8 -*- import logging logger = logging.getLogger() #定义一个log日志对象 hdlr = logging.FileHa ...
- Ubuntu下使用rpm 软件包
Ubuntu的软件包格式是deb,如果要安装rpm的包,则要先用alien把rpm转换成deb. sudo apt-get install alien sudo alien xxxx.rpm #将rp ...
- Javascript模块化编程:AMD规范及require.js用法【转】 - loheonly的笔记 - 前端网(W3Cfuns)
http://www.w3cfuns.com/blog-5425789-5399326.html
- IIS判断W3WP进程对应哪个网站
IIS 6 (Win2003 )中查看某个应用程序池对应那个 W3WP.exe 进程,可以使用如下命令,输出结果类似如下: C:\WINDOWS\system32>cscript iisapp. ...
- string 与wstring 的转换
std::wstring StringToWString(const std::string &str) { std::wstring wstr(str.length(),L' '); std ...
- Not a million dollars ——a certain kind of ingenuity, discipline, and proactivity that most people seem to lack
原文:http://ryanwaggoner.com/2010/12/you-dont-really-want-a-million-dollars/a certain kind of ingenuit ...