1.基本类
//smarty_config.php
<?php
define('TEMPLATE_DIR','templates/');
define('COMPILE_DIR','templates_c/');
define('CONFIG_DIR','configs/');
define('CACHE_DIR','cache/');
?>
//View.class.php
<?php
//配置文件
require_once 'configs/smart_config.php';
//Smarty类
require('smarty/Smarty.class.php');
class View extends Smarty {
function SmartyFactory() {
$this->Smarty();
//模板路径
$this->template_dir = TEMPLATE_DIR;
//编译后文件
$this->compile_dir = COMPILE_DIR;
//配置文件
$this->config_dir = CONFIG_DIR;
//缓存文件
$this->cache_dir = CACHE_DIR;
$this->debugging = true;
}
//重新封装display 个人习惯改成show
function show($name,$cacheId='') {
if($cacheId == '')
$this->display($name.'.htm');
else
$this->display($name.'.htm',$cacheId);
}
//重新封装assign 习惯用add
function add($name,$value) {
$this->assign($name,$value);
}
}
?>
基本目录如:
test
|-configs
|-templates
|-templates_c
|-cache
|-smarty --smarty lib
2.基本使用
//index.php
<?php
require_once('View.php');
//数据查询 mysql_fetch_assoc() 返回数组
//数据库层封装
//如:$User = new User();
//$Users = $User->paging('参数');
$View = new View();
$View->add("users",$Users);
$View->show("index");
?>
//public.conf
[public]
public = public/
img = public/img/
css = public/css/
js = public/js/
//index.htm --在templates文件夹下 简短介绍下
<html>
<!-- 包含meta.htm文件-->
{include file="meta.htm"}
<!-- 利用smarty config文件 定义基本信息-->
{config_load file=public.conf section="public"}
<!-- 略 -->
<table>
<tr>
<!-- {#img#} img的基本路径 对于一般小网站的做法 如有是使用了二级域名的静态服务器没必要了-->
<td><input type="image" src="{#img#}xxx.gif"/></td>
</tr>
</table>
<table>
<tr>
<td>id</td><td>用户名</td>
</tr>
<!-- 循环遍历 数组里的数据 -->
<!-- loop=$Users 在php中的变量 name=user循环的名称-->
{section name=user loop=$Users}
<tr>
<td>{$Users[user].id}</td>
<td>{$Users[user].username}</td>
</tr>
{/section}
</table>
<!-- 包含另一个php 这个php可以是index.php这样的模板输出-->
{php}
include("other.php");
{/php}
</html>
分享到:
相关推荐
1. PHP的基本语法。 2. SMARTY的使用。 3. 环境的搭建。 4. 第一个示例。 http://blog.csdn.net/dengxingbo/archive/2009/08/16/4450808.aspx
自制的一个包含smarty组件的php网站框架,其中基本框架已经搭建好了,首页模板,smarty配置已经配好了,是初学者建站php 学习smaryt的好资料
基本文件文件结构 index.php /libs/ Smarty.class.php #主文件 /libs/sysplugins/ #内部plugin internal.* /plugins/ #外部plugin,可自由扩充 function.mailto.php modifier.escape.php /templates/ #模板,可以...
Variables assigned from PHP [从PHP分配的变量] Variables loaded from config files [从配置文件读取的变量] {$smarty} reserved variable [{$smarty}保留变量] 5. Variable Modifiers [变量调节器] ...
Smarty/PHP errors [Smarty/PHP 错误] 18. Tips & Tricks [使用技巧和经验] Blank Variable Handling [空白变量处理] Default Variable Handling [默认变量处理] Passing variable title to header template ...
Smarty/PHP errors [Smarty/PHP 错误] 18. Tips & Tricks [使用技巧和经验] Blank Variable Handling [空白变量处理] Default Variable Handling [默认变量处理] Passing variable title to header template ...
Smarty 模板引擎教程 chm格式,内容主要有基本语法、变量、组合修改器、内建函数、自定义函数、配置文件、控制台调试、缓存、插件扩展、使用技巧和经验等,比较详细的一个中文手册,如上图示。
smarty4j是一个smarty for java的模板引擎,该引擎是将smarty模板从php上移植过来,需要asm-3.0.jar。smarty4j将文本解析成语法树,然后根据语法树生成Java Code的字节码,相当于一个基于JVM的smarty语法的编译器。...
后台管理程序由php开发,目前只实现了基本功能:模块管理...使用codeigniter框架和Smarty模板 页面使用ACE Admin UI模板,为了结合frame做了二次修改 图形报表使用openflashchart,OFC php有不少BUG,我已经做了修复
PHP 的基本 MVC 框架,它使用 Smarty 模板引擎和开放模式数据库(基于数据模型)。 将以下内容添加到您的 .htaccess 或 Apache 配置中: 重写引擎开启 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{...
smarty是一个使用PHP写出来的模板PHP模板引擎,它提供了逻辑与外在内容的分离,简单的讲,目的就是要使用PHP程序员同美工分离,使用的程序员改变程序的逻辑内容不会影响到美工的页面设计,美工重新修改页面不会影响到...
smarty4j是一个smarty for java的模板引擎,该引擎是将smarty模板从php上移植过来,需要asm-3.0.jar。 smarty4j将文本解析成语法树,然后根据语法树生成Java Code的字节码,相当于一个基于JVM的smarty语法的编译器...
phP ADO 的基本资料,大家自己仔细学习phP ADO 的基本资料,大家自己仔细学习
学习php手册大全,都是chm格式的啊 部分 前言 作者和贡献者 I....1. 简介 2. 简明教程 II....3. 安装前需要考虑的事项 4. Unix 系统下的安装 5. Mac OS X 系统下的安装 ...……php ...I....1. What is Smarty?...……smarty
模板设计者篇 Table of Contents[内容列表] 3. Basic Syntax [基本语法] 4. Variables [变量] 5. Variable Modifiers [变量修改器] ...16. Extending Smarty With Plugins [利用插件扩展Smarty]
主要介绍了php封装的smarty类,针对Smarty的基本操作技巧进行了封装整理,具有一定参考借鉴价值,需要的朋友可以参考下
php5 chm,mysql5 chm,js chm,css3 chm,smarty chm,smarty大师兄 chm,dom 文档对象模型 chm基本上php网络开发的chm我都有哈,如有需要邮件aaaa_2668@sina.com不过先得下下来,给我分哈。再邮件问我有没有其他的,,
网络框架只是无聊地为网站构建框架,这确实需要很多时间。 为此,我将使用 PHP MySQL BootStrap Smarty 构建基本的网站框架,当然也会提供一些演示。
本书从初学者角度出发,通过通俗易懂的语言,丰富多彩的实例,详细介绍了使用PHP进行网络开发应该掌握的各方面技术。全书共分24章,包括初识PHP、PHP环境搭建和开发工具、PHP语言基础、流程控制语句、字符串操作、...
php模板解决方案,大多数都只是提供了用模板取代变量和将动态区块的功能有限的格式化的基本方法。但是我们的需求比这个要高的多。我们完全不想要php程序员去设计html页面,可是这又是不可避免的。