rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 程序开发 » PHP

smarty的路径

安装smarty(最重要的是路径,让我头疼几天就是因为路径不对)
    首先下载最新版本的Smarty。解压下载的文件(目录结构还蛮复杂的)。接下来我演示给大家一个安装实例,看过应该会举一反三的。
   (1) 我在根目录下建立了新的目录demo,再在demo里建立一个目录smarty。将刚才解压缩出来的目录的libs拷贝到smarty里,再在smarty里新建templates目录,templates里新建cache,templates,templates_c, config
   (2) 新建一个模板文件:index.html,将此文件放在demo/smarty/templates/templates目录下,代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type" c>
<title>Smarty</title>
</head>
<body>
{$hello}
</body>
</html>
新建index.php,将此文件放在demo下:
<?php
//引用类文件
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;
//设置各个目录的路径,这里是安装的重点
$smarty->template_dir ="smarty/templates/templates";
$smarty->compile_dir ="smarty/templates/templates_c";
$smarty->config_dir = "smarty/templates/config";
$smarty->cache_dir ="smarty/templates/cache";
//smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决
$smarty->caching = false;
$hello = "Hello World!";
//赋值
$smarty->assign("hello",$hello);
//引用模板文件
$smarty->display('index.html');
?>
(3) 执行index.php就能看到Hello World!了。
顶一下
(0)
踩一下
(0)