phplib如何包括文件

freescy2002 2004-07-31 11:44:10
以前html和php混编的时候使用include就可以包括一个文件 ,现在使用phplib后,php跟html分离后,将html放在单独的文件夹内,然后

$top=require("Template/top.htm");
include "Template/template.inc";
$t = new Template();
$t->set_file("MyFileHandle","Template/reg.htm");
$t->set_var("top",$top);
$t->parse("MyOutput","MyFileHandle");
$t->p("MyOutput");

在reg.htm
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
{top}
<body>
</body>
</html>

不会显示那个top.htm.为什么,谢谢了。
...全文
107 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccterran 2004-08-01
  • 打赏
  • 举报
回复
嘿嘿。
freescy2002 2004-08-01
  • 打赏
  • 举报
回复
多谢大哥,小弟先结分,多谢多谢,好好学学。多谢多谢。
ccterran 2004-08-01
  • 打赏
  • 举报
回复
干吗要修改成$t->set_file("MyFileHandle","Template/reg.htm");?

刚才我也写错了,应该是

include "Template/template.inc"; //引用文件
$t = new Template("Template"); //新的对象,设定Template为模板根目录
$t->set_file("MyFileHandle","reg.htm"); //主模板
$t->set_file("_top", "top.htm");//头部模板
$t->parse("top","_top"); //头部分析结果赋予变量top
$t->parse("MyOutput","MyFileHandle"); //分析整个模板
$t->p("MyOutput");//输出

freescy2002 2004-08-01
  • 打赏
  • 举报
回复
大哥,小弟先说一下各个文件 的位置
根目录下面有reg.php,而
reg.htm top.htm template.inc
放在文件放在Template文件夹里面,

我把那个
$t->set_file("MyFileHandle","reg.htm");
修改为

$t->set_file("MyFileHandle","Template/reg.htm");
后,错误 为下
Template Error: filename: file Template/Template/reg.htm does not exist.
Halted.
ccterran 2004-08-01
  • 打赏
  • 举报
回复
啊,不是吧,有什么错误提示吗?

freescy2002 2004-08-01
  • 打赏
  • 举报
回复
ccterran(iwind)
你这样的写法,小弟怎么无法运行。谢谢了。
ccterran 2004-07-31
  • 打赏
  • 举报
回复
不是这样用的。

include "Template/template.inc";
$t = new Template("Template");
$t->set_file("MyFileHandle","reg.htm");
$t->set_file("_top", "top.htm");
$t->set_var("top","_top");
$t->parse("MyOutput","MyFileHandle");
$t->p("MyOutput");

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧