PHP Smarty template for website
/******************************************************************************
* 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的更多相关文章
- Smarty的基本使用与总结
含义: Smarty是PHP的一个引擎模板,可以更好的进行逻辑与显示的分离,即我们常说的MVC,这个引擎的作用就是将C分离出来. 环境需求:PHP5.2或者更高版本 我使用的环境是:PHP5.3,wi ...
- 12月15日smarty模板基本语法
smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...
- SMARTY模板中如何使用get,post,request,cookies,session,server变量
{$smarty}保留变量不需要从PHP脚本中分配,是可以在模板中直接访问的数组类型变量,通常被用于访问一些特殊的模板变量.例如,直接在模板中访问页面请求变量.获取访问模板时的时间戳.直接访问PHP中 ...
- Smarty模板技术学习
模板引擎技术:使得php代码和html代码分离的技术就称为"模板引擎技术" 自定义smarty模板技术实现 <?php //迷你smarty原理 class MiniSmar ...
- smarty基本语法
smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...
- php基础复习(一)smarty模板
一.基本配置第一步:下载smarty:官网www.smarty.net第二步:加载类文件和更改配置 1. //加载类文件 require_once '../libs/Smarty.class.php' ...
- 框架开发(三)---smarty整合
一 smarty 是什么 Smarty是一个PHP的模板引擎.更明确来说,它可以帮助开发者更好地 分离程序逻辑和页面显示.最好的例子,是当程序员和模板设计师是不同的两个角色的情况,而且 大部分时候都不 ...
- 前端学PHP之Smarty模板引擎
前面的话 对PHP来说,有很多模板引擎可供选择,但Smarty是一个使用PHP编写出来的,是业界最著名.功能最强大的一种PHP模板引擎.Smarty像PHP一样拥有丰富的函数库,从统计字数到自动缩进. ...
- smarty模板基本语法
smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...
随机推荐
- Nginx常用命令(加入系统服务)
nginx 服务器重启命令,关闭 nginx -s reload :修改配置后重新加载生效 nginx -s reopen :重新打开日志文件 nginx -t -c /path/to/nginx.c ...
- 【转】通过fio工具,测试SATA,SAS,SSD 读写性能
转自:http://blog.csdn.net/killmice/article/details/42745937
- UI控件之UIView与动画
UIView:用来展示用户的界面,响应用户的操作(继承自UIResponder) UIView的作用:绘图.动画.处理事件 UIView可以包含和管理子视图,并且决定子视图的位置大小 获取所有的子视图 ...
- 【LeetCode】【定制版排序】Sort Colors
之前转载过一篇STL的sort方法底层详解的博客:https://www.cnblogs.com/ygh1229/articles/9806398.html 但是我们在开发中会根据自己特定的应用,有新 ...
- sql中in和exists的区别效率问题 转
in 和exists in是把外表和内表作hash 连接,而exists 是对外表作loop 循环,每次loop 循环再对内表进行查询. 一直以来认为exists 比in 效率高的说法是不准确的.如果 ...
- eclipse新建自定义EL函数
==================================================================================================== ...
- 【HackerRank】QuickSort(稳定快排,空间复杂度O(n))
QuickSort In the previous challenge, you wrote a partition method to split an array into 2 sub-array ...
- verilog中一些基本的门电路如pmos和nmos等
最近在分析波形的时候,发现某个PAD模型的行为与想象的不一致,就进入stdcell里面看了下,主要是pmos和nmos相关的东西,暂列如下: 开关级基元14种 是实际的MOS关的抽象表示,分电阻型(前 ...
- K8s + Flannel 网络架构图
这是Flannel官网给出的网络架构图 这是通过自己的理解画的逻辑结构图 查看bridge [root@node01 ~]# brctl show bridge name bridge id STP ...
- poj 1273 ---&&--- hdu 1532 最大流模板
最近在换代码布局,因为发现代码布局也可以引起一个人的兴趣这个方法是算法Edmonds-Karp 最短增广路算法,不知道的话可以百度一下,基于Ford-Fulkerson算法的基础上延伸的 其实我不是很 ...