教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 笑谈Smarty技术配置与应用

笑谈Smarty技术配置与应用

发布时间:2015-06-03   编辑:jiaochengji.com
笑谈Smarty技术配置与应用,确实很平常的一篇技术文章,不过新手朋友还是可以参考学习下的。1: 下载模板库文件: http://smarty.php.net/download.php

笑谈Smarty技术配置与应用,确实很平常的一篇技术文章,不过新手朋友还是可以参考学习下的。

1: 下载模板库文件: http://smarty.php.net/download.php

下载后解压,得到形如 smarty.x.x的文件夹,找开查看,里面有个libs 文件夹,就是我们需要的了。

2: 在网站目录下面,比方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里面的
<B>

; Windows: "path1;path2"
include_path = ".;c:phpincludes"

</B>
改为:
------------------->
; Windows: "path1;path2"
include_path = ".;c:phpincludes;d:webwebphplibs"
使用模板的时候,像前面一样的方式使用,不要
include "../libs/Smarty.class.php";
直接使用可以了。

您可能感兴趣的文章:
smarty获得当前url示例代码
笑谈Smarty技术配置与应用
smarty缓存应用与清除
smarty 模板if else使用实例与入门教程
php smarty 基础
PHP模板引擎Smarty缓存使用
PHP生成静态页面注意几点
有关smarty的基本设置
有关smarty缓存的应用
smarty结合xajax检测用户名

[关闭]
~ ~