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-笔记的更多相关文章

  1. Smarty3学习笔记

    Smarty3 笔记 By 飞鸿影~ -- :: Smarty入门 1.什么是smarty? Smarty是采用php写的一个模版引擎,设计的目的是要将php代码与html代码分离, 使php程序员只 ...

  2. git-简单流程(学习笔记)

    这是阅读廖雪峰的官方网站的笔记,用于自己以后回看 1.进入项目文件夹 初始化一个Git仓库,使用git init命令. 添加文件到Git仓库,分两步: 第一步,使用命令git add <file ...

  3. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  4. SQL Server技术内幕笔记合集

    SQL Server技术内幕笔记合集 发这一篇文章主要是方便大家找到我的笔记入口,方便大家o(∩_∩)o Microsoft SQL Server 6.5 技术内幕 笔记http://www.cnbl ...

  5. PHP-自定义模板-学习笔记

    1.  开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2.  整体架构图 ...

  6. PHP-会员登录与注册例子解析-学习笔记

    1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...

  7. NET Core-学习笔记(三)

    这里将要和大家分享的是学习总结第三篇:首先感慨一下这周跟随netcore官网学习是遇到的一些问题: a.官网的英文版教程使用的部分nuget包和我当时安装的最新包版本不一致,所以没法按照教材上给出的列 ...

  8. springMVC学习笔记--知识点总结1

    以下是学习springmvc框架时的笔记整理: 结果跳转方式 1.设置ModelAndView,根据view的名称,和视图渲染器跳转到指定的页面. 比如jsp的视图渲染器是如下配置的: <!-- ...

  9. 读书笔记汇总 - SQL必知必会(第4版)

    本系列记录并分享学习SQL的过程,主要内容为SQL的基础概念及练习过程. 书目信息 中文名:<SQL必知必会(第4版)> 英文名:<Sams Teach Yourself SQL i ...

随机推荐

  1. 添加一个Application Framework Service

    如何添加一个Application Framework Service(without native code)? 1.本文参照AlarmManagerService实现一个简单的Applicatio ...

  2. android Actionmode 样式自定义

    <style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar" ...

  3. Problem A

    Problem A Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  4. 转:LoadRunner中参数化技术详解

    LoadRunner中参数化技术详解 LoadRunner在录制脚本的时候,只是忠实的记录了所有从客户端发送到服务器的数据,而在进行性能测试的时候,为了更接近真实的模拟现实应用,对于某些信息需要每次提 ...

  5. HDU 2475 BOX 动态树 Link-Cut Tree

    Box Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [Problem De ...

  6. github 教程

    http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/

  7. 关于MyEclipse不停报错multiple problems have occurred 或者是内存不足 的解决办法

    这是因为 worksapace与svn代码不一样,要更新! 一更新就好了,困扰死我了,卧槽,搞了2个小时,难怪svn一提交就卡死人,原来还就是svn的问题,更新一下就行.

  8. apache RewriteCond RewriteRule

    http://www.rockbb.com/blog/?p=319 http://www.cnblogs.com/scgw/archive/2011/12/10/2283029.html 我的理解:当 ...

  9. Why attitude is more important than IQ

    原文:http://www.businessinsider.com/why-attitude-is-more-important-than-iq-2015-9?IR=T& LinkedIn I ...

  10. Binary Watch

    Binary Watch 描述 Consider a binary watch with 5 binary digits to display hours (00 - 23) and 6 binary ...