/******************************************************************************
* 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. C#类和结构(1)

    1.结构功能特性? 实现代码? 结构用struct关键字定义的,与类类似,但有本质区别.结构实质是一个值类型,它不需要对分配的. 结构的特性: (1).结构作为参数传递时,是值传递. (2).结构的构 ...

  2. python——单例模式

    单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在. 当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. 比如, ...

  3. 【转】Python爬虫_示例2

    爬虫项目:爬取并筛选拉钩网职位信息自动提交简历   一 目标站点分析 #一:实验前准备: 浏览器用Chrome 用Ctrl+Shift+Delete清除浏览器缓存的Cookie 打开network准备 ...

  4. 系统非正常关机启动后出现:an error occurred during the file system

    现象描述: 1.系统ssh登录报Too many open files in system,系统登录不进去,就直接强制关机了,开机后出现(2)的错误: 由于文件描述符用完了,需要把fs.file-ma ...

  5. active admin

    activeadmin 1.0.0.pre4 所依赖的库 gem 'jquery-rails', '~> 4.0.4' 4.2版本会出现找不到jquery-ui 的datepicker错误 使用 ...

  6. javascript;select动态添加和删除option

    <select id="sltCity"></select> //添加Option. var optionObj = new Option(text, va ...

  7. jquery图片过滤归类应用

    在线演示 本地下载

  8. oracle 序列改值

    1.oracle 序列改值 执行:Alter Sequence SQ_RM_FRAME Increment By 100; 执行:Select SQ_RM_FRAME.NextVal From Dua ...

  9. Mysql -- You can't specify target table 'address' for update in FROM clause

    做地址管理时,需要先根据要设为默认的地址的用户将用户的其他地址都设置为非默认 需要select出用户id然后update 原语句 update address set isdeafult = 0 wh ...

  10. mysql基础(2)-数据处理(mysql+pandas)

    插入语句insert insert  数据表名(字段名...) values(字段值): 例 : insert into new_student values("张"," ...