当前位置: 首页 > news >正文

PHP Smarty template for website

/******************************************************************************
 *                        PHP Smarty template for website
 * 说明:
 *     之前一直在想将MVC的方式加在PHP做的网站上,这样比较好处理,相对来说比较好
 * 处理,这样后续维护会比较好。
 *
 *                                         2017-3-12 深圳 南山平山村 曾剑锋
 *****************************************************************************/

一、参考文档:
    1. Smarty教程
        http://www.yiibai.com/smarty/
    2. smarty template engine
        http://www.smarty.net/
    3. Parsing JSON file with PHP 
        http://stackoverflow.com/questions/4343596/parsing-json-file-with-php

二、Smarty Download:
    1. gz file: https://github.com/smarty-php/smarty/archive/v3.1.30.tar.gz
    2. zip file: https://github.com/smarty-php/smarty/archive/v3.1.30.zip
    
三、配置:
    1. 使用相对路径加入当前项目;
    2. 使用require_once('<path to Smarty.class.php>'):
        <?php
        // NOTE: Smarty has a capital 'S'
        require_once('<path to Smarty.class.php');
        $smarty = new Smarty();
        ?>
    3. template文件后缀名: <file name>.tpl
    4. 注释:
        {* comments *}
    5. 赋值变量:
        $smarty->assign('name','Ned');
    6. 使用:
        {$name}
    7. 处理模板:
        $smarty->display('index.tpl');
    8. 打开debug模式:
        $smarty->debugging = true;
    9. 继承class smarty,扩展功能:
        <?php

        // load Smarty library
        require('Smarty.class.php');

        // The setup.php file is a good place to load
        // required application library files, and you
        // can do that right here. An example:
        // require('guestbook/guestbook.lib.php');

        class Smarty_GuestBook extends Smarty {

           function __construct()
           {

                // Class Constructor.
                // These automatically get set with each new instance.

                parent::__construct();

                $this->setTemplateDir('/web/www.example.com/guestbook/templates/');
                $this->setCompileDir('/web/www.example.com/guestbook/templates_c/');
                $this->setConfigDir('/web/www.example.com/guestbook/configs/');
                $this->setCacheDir('/web/www.example.com/guestbook/cache/');

                $this->caching = Smarty::CACHING_LIFETIME_CURRENT;
                $this->assign('app_name', 'Guest Book');
           }

        }
        ?>
    10. 继承使用:
        <?php

        require('guestbook/setup.php');

        $smarty = new Smarty_GuestBook();

        $smarty->assign('name','Ned');

        $smarty->display('index.tpl');
        ?>
    11. 解析JSON文件当配置文件,将数据放入smarty对象中,这样就好配置了。

 

相关文章:

  • 网络中数据传输过程的分析
  • BIO、NIO和AIO的区别(简明版)
  • JavaScript-基础入门.0008.JavaScript作用范围
  • 《微信公众平台开发》图书介绍
  • PE分析
  • 判断用户名是否正确
  • loadrunner中Windows Resource没有数据或不可用
  • vue-todolist-example学习
  • javaScript事件(八)事件类型之变动事件
  • 白话机器学习
  • JavaScript的异步运行机制
  • 嵌入式软件设计第7次实验报告
  • 从@property说起(二)当我们写下@property (nonatomic, weak) id obj时,我们究竟写了什么...
  • httpclient 优化
  • PHPCMSV9上线方法及文件权限设置
  • 收藏网友的 源程序下载网
  • 【5+】跨webview多页面 触发事件(二)
  • CSS盒模型深入
  • github指令
  • JavaSE小实践1:Java爬取斗图网站的所有表情包
  • java小心机(3)| 浅析finalize()
  • Objective-C 中关联引用的概念
  • React16时代,该用什么姿势写 React ?
  • Selenium实战教程系列(二)---元素定位
  • SQLServer之创建数据库快照
  • vue--为什么data属性必须是一个函数
  • windows-nginx-https-本地配置
  • 实现菜单下拉伸展折叠效果demo
  • 听说你叫Java(二)–Servlet请求
  • 我看到的前端
  • 携程小程序初体验
  • 学习ES6 变量的解构赋值
  • 中国人寿如何基于容器搭建金融PaaS云平台
  • ​一文看懂数据清洗:缺失值、异常值和重复值的处理
  • #pragma multi_compile #pragma shader_feature
  • #我与Java虚拟机的故事#连载19:等我技术变强了,我会去看你的 ​
  • (ibm)Java 语言的 XPath API
  • (非本人原创)史记·柴静列传(r4笔记第65天)
  • (数据结构)顺序表的定义
  • (数位dp) 算法竞赛入门到进阶 书本题集
  • (四)七种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (一)基于IDEA的JAVA基础1
  • (一一四)第九章编程练习
  • (转载)跟我一起学习VIM - The Life Changing Editor
  • (状压dp)uva 10817 Headmaster's Headache
  • .【机器学习】隐马尔可夫模型(Hidden Markov Model,HMM)
  • .class文件转换.java_从一个class文件深入理解Java字节码结构
  • .NET 的程序集加载上下文
  • .NET/C# 解压 Zip 文件时出现异常:System.IO.InvalidDataException: 找不到中央目录结尾记录。
  • [ NOI 2001 ] 食物链
  • [.net 面向对象程序设计进阶] (19) 异步(Asynchronous) 使用异步创建快速响应和可伸缩性的应用程序...
  • [20171106]配置客户端连接注意.txt
  • [AHOI2009]中国象棋 DP,递推,组合数
  • [AutoSar]BSW_Memory_Stack_004 创建一个简单NV block并调试
  • [Cocoa]iOS 开发者账户,联机调试,发布应用事宜