/******************************************************************************
* 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. windows安装pywin32

    下载旧版 https://sourceforge.net/projects/pywin32/files/pywin32/ 下载新版 https://github.com/mhammond/pywin3 ...

  2. Android Integer.parseInt java.lang.NumberFormatException: Invalid int解决方法

    解决方法: http获取的字符串minutes去空字符串处理minutes.replaceAll("\\D+","").replaceAll("\r& ...

  3. 一种基于自定义代码的asp.net网站访问IP过滤方法!

    对于一些企业内部核心系统,特别是外网访问的时候,为了信息安全,可能需要对外部访问的IP地址作限制,虽然IIS中也提供了根据IP地址或IP地址段进行限制或允许,但并没有提供根据IP地址所在的城市进行限制 ...

  4. 关于java登录界面

    import java.awt.*; 包含用于创建用户界面和绘制图形图像的所有类.   import javax.swing.*; 提供一组“轻量级”(全部是 Java 语言)组件,尽量让这些组件在所 ...

  5. 027_编写MapReduce的模板类Mapper、Reducer和Driver

    模板类编写好后写MapReduce程序,的模板类编写好以后只需要改参数就行了,代码如下: package org.dragon.hadoop.mr.module; import java.io.IOE ...

  6. 【Tech】POI标签分类

    寒假老板给的任务,让我重现这个实验http://www.liuhaihua.cn/archives/15565.html.自己就随便试了下,用的都是比较经典(lao)的算法和知识,记录一下. 一.从网 ...

  7. nodejs异步调用async

    犹豫nodejs是异步编程模型,有一些在同步编程中很容易做到的事情,现在却变得很麻烦,async的流程控制就是为了简化这些操作var async = require('async'); 1.serie ...

  8. 支持鼠标拖拽滑动的jQuery焦点图

    在线演示 本地下载

  9. USB引脚及定义

    USB 2.0 USB接口定义: USB引脚定义: 针脚 名称 说明 接线颜色 1 VCC +5V电压 红色 2 D- 数据线负极 白色 3 D+ 数据线正极 绿色 4 GND 接地 黑色   Min ...

  10. uiwebview 加载本地js、css、img,html从网站加载

    资源文件都是放在根目录下 1.index.html <html> <head> <title>My test Page</title> <link ...