简单php 模板引擎 smarty 不明白

来源:百度知道 编辑:UC知道 时间:2024/05/26 07:50:49
一个最最简单的应用smarty 的实例操作,却莫名出错,晕死中。。
我写一个简单demoa.php文件如下 :
<?php
include("Smarty_inc.php");

$name[]=array("name"=>"ff","date"=>"09-08-16");
$name[]=array("name"=>"fdf","date"=>"09-08-17");
$name[]=array("name"=>"weew","date"=>"09-08-18");
$row=array("中国","日本","韩国");
$smarty->assign("title",$name);
$smarty->assign("row",$row);
$smarty->display("demo1.htm");
?>

然后下面就是用到的demo1.htm模板:
<html>
{section name=list loop=$title}
<b><font color=red>
{$title[list].name - $title[list].date}
</font></b><br>
{/section}
<hr>
<h1>{$row[0]}
<h2>{$row[1]}
</html>

小弟有几点不明白:
1,是该运行demoa.

运行demoa.php 你想知道怎么做 我的空间里有详细的使用说明
http://hi.baidu.com/zchare/blog/item/9c4bda07154255c47a894745.html
自己看吧

如果你的html页面和php页面在同个目录下时,请用下面这句设定路径
$smarty->template_dir = './';/*把这个加在include("Smarty_inc.php");下面就行了*/

朋友,你上面的smarty 用法用错了。可以看看php100里面好像是26---30讲关于smarty 模板引擎技术。我用smarty 不是你这样用的~!
关于 section 我也基本不用
{section name=list loop=$title},这一句可以不要
下面应该可以直接输出{$row.name}吧

看看是不是路径问题

例如:html模版文件是放在Templates文件夹下的。如果运行时Templates下没有对应的html文件,就会提示unable to read resource: "demo1.htm"----demo1.html无法读取。

看一下文件路径.

推荐你看php100里面的smarty视频教程,当然运行php文件了,另外绝对不是Smarty.class.php出错,肯定是你写的不对,我遇到过这种情况,结果还是我的代码有错误,把loop=$title改成loop=$arr试试,另外php里面的家上$arr[]=$row和$smarty->assign("arr",$arr);
我用smarty不多,你试试吧。。。