初识smarty简单配置
2009-04-27 15:47
267 查看
Smarty技术是PHP的精髓所在,随着PHP版本的逐渐提高,原来的很多方法也许太过时了,下面我就针对最新的PHP5.1.1版本的使用,配置说说如何配置。
下面是一步步的来的,请注意:
1、在官方下载模板库文件: http://smarty.php.net/download.php
下载了就解压,看见一个文件夹了,是个 smarty.x.x,打开,里面有个libs 文件夹,ok,注意这个东西就是我们要的。
2、在你的网站目录下面,比方我的php网站IIS在物理硬盘的 d:/web/web/php下面,在这个文件夹下面建立:一个文件夹 test,然后我们把刚提到的 libs文件夹复制道test 文件夹下面。{ * 请看本文最后的注释 TIPS1}
3、在test 文件夹下面再建立4个文件夹:
cache
configs
templates
templates_c
4、建立文件 text.htm:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><{$title}></title>
</head>
<body>
<{$content}>
</body>
</html>
保存在 templates 目录下面。
5、然后建立文件模板配置文件: config.php
<?php
include "libs/Smarty.class.php";
$NowPathArray=explode("test",str_replace("//","/",dirname(__FILE__))) ;
@define("root_path", $NowPathArray[0]);
@define('__SITE_ROOT', root_path."test");
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/templates/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$tpl->config_dir = __SITE_ROOT . "/configs/";
$tpl->cache_dir = __SITE_ROOT . "/cache/";
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
?>
保存在主目录也就是 test下面。
6、在test新建文件test.php文件,输入:
<?php
require "config.php";
$tpl->assign("title", "测试成功了,这是标题");
$tpl->assign("content", "这是内容");
$tpl->display('test.htm');
?>
7、在浏览器测试test.php显示为:
这是内容
恭喜,配置成功.否则,失败,再检查是不是按照我说的来的。
Tips1 :为了能在网站全局使用Smarty技术,我们可以修改PHP.inc里面的
; Windows: "/path1;/path2"
include_path = ".;c:/php/includes"
改为:
; Windows: "/path1;/path2"
include_path = ".;c:/php/includes;d:/web/web/php/libs"
使用模板的时候,像前面一样的方式使用,不要:
include "libs/Smarty.class.php";
直接使用就行了的。
下面是一步步的来的,请注意:
1、在官方下载模板库文件: http://smarty.php.net/download.php
下载了就解压,看见一个文件夹了,是个 smarty.x.x,打开,里面有个libs 文件夹,ok,注意这个东西就是我们要的。
2、在你的网站目录下面,比方我的php网站IIS在物理硬盘的 d:/web/web/php下面,在这个文件夹下面建立:一个文件夹 test,然后我们把刚提到的 libs文件夹复制道test 文件夹下面。{ * 请看本文最后的注释 TIPS1}
3、在test 文件夹下面再建立4个文件夹:
cache
configs
templates
templates_c
4、建立文件 text.htm:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><{$title}></title>
</head>
<body>
<{$content}>
</body>
</html>
保存在 templates 目录下面。
5、然后建立文件模板配置文件: config.php
<?php
include "libs/Smarty.class.php";
$NowPathArray=explode("test",str_replace("//","/",dirname(__FILE__))) ;
@define("root_path", $NowPathArray[0]);
@define('__SITE_ROOT', root_path."test");
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/templates/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$tpl->config_dir = __SITE_ROOT . "/configs/";
$tpl->cache_dir = __SITE_ROOT . "/cache/";
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
?>
保存在主目录也就是 test下面。
6、在test新建文件test.php文件,输入:
<?php
require "config.php";
$tpl->assign("title", "测试成功了,这是标题");
$tpl->assign("content", "这是内容");
$tpl->display('test.htm');
?>
7、在浏览器测试test.php显示为:
这是内容
恭喜,配置成功.否则,失败,再检查是不是按照我说的来的。
Tips1 :为了能在网站全局使用Smarty技术,我们可以修改PHP.inc里面的
; Windows: "/path1;/path2"
include_path = ".;c:/php/includes"
改为:
; Windows: "/path1;/path2"
include_path = ".;c:/php/includes;d:/web/web/php/libs"
使用模板的时候,像前面一样的方式使用,不要:
include "libs/Smarty.class.php";
直接使用就行了的。
相关文章推荐
- (二)初识springboot之使用fastjson解析数据(解决乱码及简单配置)
- 初识MyBatis(如何写配置文件和简单使用)
- 初识php 环境的配置和简单的get post
- 初识solr 安装单节点solr5.5.3 配置中文分词 以及简单使用
- 初识Hibernate及简单的手动创建配置文件
- Smarty3.1.18的配置和简单使用
- PHP模板引擎Smarty(一)Smarty下载、配置、一个最简单的应用示例
- 从java bean配置初识spring 实现最简单的Helloworld
- 简单的smarty安装配置笔记
- PHP SMARTY 简单配置
- Smarty模板简单配置与使用方法示例
- lvs初识与简单配置
- 【duilib界面库】duilib界面库(1)初识duilib界面库及编译配置详解
- Smarty 配置文件中的相对路径
- 【mybatis】入门 - 基本配置、简单示例
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- OSPF的简单配置
- Ubuntu12.04在无网络环境下配置apt-get光盘源的简单方法
- PHP sendmail的配置与简单测试
- Struts+Spring+JDBC 简单配置