/******************************************************************************
* PHP Smarty template for website
* 说明:
* 之前一直在想将MVC的方式加在PHP做的网站上,这样比较好处理,相对来说比较好
* 处理,这样后续维护会比较好。
*
* 2017-3-12 深圳 南山平山村 曾剑锋
*****************************************************************************/ 一、参考文档:
. Smarty教程
http://www.yiibai.com/smarty/
. smarty template engine
http://www.smarty.net/
. Parsing JSON file with PHP
http://stackoverflow.com/questions/4343596/parsing-json-file-with-php 二、Smarty Download:
. gz file: https://github.com/smarty-php/smarty/archive/v3.1.30.tar.gz
. zip file: https://github.com/smarty-php/smarty/archive/v3.1.30.zip 三、配置:
. 使用相对路径加入当前项目;
. 使用require_once('<path to Smarty.class.php>'):
<?php
// NOTE: Smarty has a capital 'S'
require_once('<path to Smarty.class.php');
$smarty = new Smarty();
?>
. template文件后缀名: <file name>.tpl
. 注释:
{* comments *}
. 赋值变量:
$smarty->assign('name','Ned');
. 使用:
{$name}
. 处理模板:
$smarty->display('index.tpl');
. 打开debug模式:
$smarty->debugging = true;
. 继承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');
} }
?>
. 继承使用:
<?php require('guestbook/setup.php'); $smarty = new Smarty_GuestBook(); $smarty->assign('name','Ned'); $smarty->display('index.tpl');
?>
. 解析JSON文件当配置文件,将数据放入smarty对象中,这样就好配置了。

PHP Smarty template for website的更多相关文章

  1. Smarty的基本使用与总结

    含义: Smarty是PHP的一个引擎模板,可以更好的进行逻辑与显示的分离,即我们常说的MVC,这个引擎的作用就是将C分离出来. 环境需求:PHP5.2或者更高版本 我使用的环境是:PHP5.3,wi ...

  2. 12月15日smarty模板基本语法

    smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...

  3. SMARTY模板中如何使用get,post,request,cookies,session,server变量

    {$smarty}保留变量不需要从PHP脚本中分配,是可以在模板中直接访问的数组类型变量,通常被用于访问一些特殊的模板变量.例如,直接在模板中访问页面请求变量.获取访问模板时的时间戳.直接访问PHP中 ...

  4. Smarty模板技术学习

    模板引擎技术:使得php代码和html代码分离的技术就称为"模板引擎技术" 自定义smarty模板技术实现 <?php //迷你smarty原理 class MiniSmar ...

  5. smarty基本语法

    smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...

  6. php基础复习(一)smarty模板

    一.基本配置第一步:下载smarty:官网www.smarty.net第二步:加载类文件和更改配置 1. //加载类文件 require_once '../libs/Smarty.class.php' ...

  7. 框架开发(三)---smarty整合

    一 smarty 是什么 Smarty是一个PHP的模板引擎.更明确来说,它可以帮助开发者更好地 分离程序逻辑和页面显示.最好的例子,是当程序员和模板设计师是不同的两个角色的情况,而且 大部分时候都不 ...

  8. 前端学PHP之Smarty模板引擎

    前面的话 对PHP来说,有很多模板引擎可供选择,但Smarty是一个使用PHP编写出来的,是业界最著名.功能最强大的一种PHP模板引擎.Smarty像PHP一样拥有丰富的函数库,从统计字数到自动缩进. ...

  9. smarty模板基本语法

    smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...

随机推荐

  1. 剑指offer 面试49题

    面试49题: 题:丑数 题目:把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N ...

  2. Java FAQ -- "Exception in thread 'main' java.lang.UnsupportedClassVersionError:"

    OS:Ubuntu 最近重新学习Java,写了一段很小的程序,如下: public class Hello{ public static void main(String args[]){ Syste ...

  3. 基于C#委托的深入分析

    1.委托的定义 委托可以看成是一种数据类型,可以用于定义变量能接受的值只能是一个方法. 委托简单的示例: namespace DelegateDemo { class Program { public ...

  4. django-admin 设计User外键,设计model

    设置外键 class profile_user(AbstractBaseUser, PermissionsMixin): company = models.ForeignKey(Company, de ...

  5. ggplot2学习总结

  6. JSP--常用指令

    1.JSP中的page指令: jsp中指令格式:<%@   指令名字    key=value    key=value   ......%> <%@ page language=& ...

  7. Windows命令行乱码问题解决

    命令 chcp功能: 显示或设置活动代码页编号 CHCP [nnn] nnn 指定代码页编号. 不加参数键入 CHCP 显示活动代码页编号. nnn指定一已有的系统字符集,该字符集在CONFIG.SY ...

  8. 分布式技术 webservice

    web service 是一个平台独立的.低耦合的.自包含的.基于编程的web的应用程序,可使用开发的XML(标准通用标记语言下的一个字表)标准来描述.发布.发现.协调和配置这些应用程序,用于开发分布 ...

  9. linux命令:mv命令

    mv命令是move的缩写,可以用来移动文件或者将文件改名(move (rename) files),是Linux系统下常用的命令,经常用来备份文件或者目录. 1.命令格式: mv [选项] 源文件或目 ...

  10. js适配器模式

    适配器模式,将一个类的接口转换成客户希望的另外一个接口.适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 系统的数据和行为都正确,但接口不符时,我们应该考虑用适配器,目的是使控制范 ...