SMARTY不是这么用的...templates文件夹是用来放模板的xxx.tpl,因为这是一种模板语言啊...
而你说的那些图片链接都是基于调用模板的那个xxx.php页面的,所以链接位置根本不用templates/images/index_01.png这样。如果PHP页面与IMAGE文件夹一个目录的话,直接写images/index_01.png就可以了。建议LZ去搜下SMARTY的介绍文章,网上有不少的。
而你说的那些图片链接都是基于调用模板的那个xxx.php页面的,所以链接位置根本不用templates/images/index_01.png这样。如果PHP页面与IMAGE文件夹一个目录的话,直接写images/index_01.png就可以了。建议LZ去搜下SMARTY的介绍文章,网上有不少的。
genshing你好,我会试试你的方法的,呵呵谢谢。
在同级下再建images放图片,不要放在templates里
而模板文件可以不用改为.tpl
不过,建意改一下好
基本用法如下:
//定义网站根目录
define("SITE_ROOT","/web/vms/");
define("WEB_ROOT","/vms");
define("IMAGE_ROOT","/vms/images");//定义smarty模板类相关配置
include SITE_ROOT."libs/Smarty.class.php";//定义数据库相关配置
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "cvs";$tpl = new Smarty();
$tpl->caching = false;
$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 = '}>';$tpl->assign("web_root",WEB_ROOT);
$tpl->assign("image_root",IMAGE_ROOT);
//定义页面title
$tpl->assign("page_title","网站TITLE");你的PHP页再include这个页,调用tpl就OK了~祝你早日搞定
$smarty->template_dir="./";
跟templates目录说byebye~
smarty/,将刚才解压出来的目录的libs/拷贝到smarty/里,再在smarty/
里新建templates目录,templates里新建cache/,templates/,templates_c/,
config/,如下图所示
--learn
--smarty
--libs
--internals
--plugins
--templates
--cache
--configs
--templates
--templates_c
2.新建一个模板文件:index.tpl 将此文件放在learn/smarty/templates/templates
目录下,代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML4.01
Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html";charset="ge2312">
<title>Smarty</title>
</head>
<body>
{$hello}
</body>
</html>
新建index.php 将此文件放在learn/下
<?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.tpl");//加载类模板
?>
注:Smarty.class.php文件定义了类$Smarty及几个常量。
3.执行index.php 就能在页面上输出"hello,world"先声明:我是抄别人的,不过我已经把一些东西改动了,你照上面的做 一定可以配置好,然后就明白SMARTY的原理了。