生成静态页面问题

zjiong 2006-06-07 05:12:08
用Smarty怎么生成静态页面,最好详细一点,本人初学模板,谢谢
...全文
281 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
颓废的老猫 2006-06-16
  • 打赏
  • 举报
回复
require('smarty/Smarty.class.php');
$t = new Smarty;
$t->assign("title","Hello World!");
$content = $t->fetch("templates/index.htm");
//这里的 fetch() 就是获取输出内容的函数,现在$content变量里面,就是要显示的内容了
$fp = fopen("html/text.html", "w");
fwrite($fp, $content);
fclose($fp);

//第二种方法:利用ob系列的函数。这里用到的函数主要是 ob_start(), ob_end_flush(), ob_get_content(),其中ob_start()是打开浏览器缓冲区的意思,打开缓冲后,所有来自PHP程序的非文件头信息均不会发送,而是保存在ob_end_flush().而这里最重要的一个函数,就是ob_get_contents(),这个函数的作用是获取缓冲区的内容,相当于上面的那个fetch(),道理一样的。代码:
ob_start();
echo "Hello World!";
$content = ob_get_contents();//取得php页面输出的全部内容
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
zjiong 2006-06-16
  • 打赏
  • 举报
回复
那我该怎么做啊?
xuzuning 2006-06-16
  • 打赏
  • 举报
回复
你起用了缓存机制,而在测试的时候缓存一般都不会过期。所以结果就不变了
kongguyoulan163 2006-06-16
  • 打赏
  • 举报
回复
有没有smarty方面的书啊
iasky 2006-06-16
  • 打赏
  • 举报
回复
看他的manual
zjiong 2006-06-16
  • 打赏
  • 举报
回复
楼上的方法能够生成静态页面,但是想要再次生成新的页面时,显示的依然是上一次生成的静态页面,怎么能让他直接生成新的页面?
indexroot 2006-06-07
  • 打赏
  • 举报
回复
这个是Manual上使用fetch()的例子
获取输出后,再用下面给出的wfile()输出成文件

<?php
include("Smarty.class.php");
$smarty = new Smarty;

$smarty->caching = true;

// only do db calls if cache doesn't exist
if(!$smarty->is_cached("index.tpl")) {

// dummy up some data
$address = "245 N 50th";
$db_data = array(
"City" => "Lincoln",
"State" => "Nebraska",
"Zip" => "68502"
);

$smarty->assign("Name","Fred");
$smarty->assign("Address",$address);
$smarty->assign($db_data);

}

// capture the output
$output = $smarty->fetch("index.tpl");

// do something with $output here


/**
* 写文件操作
*
* @access public
* @param bool
* @return void
*/
function wfile($file,$content,$mode='w') {
$oldmask = umask(0);
$fp = fopen($file, $mode);
if (!$fp) return false;
fwrite($fp,$content);
fclose($fp);
umask($oldmask);
return true;
}

wfile("index.html",$output)
//echo $output;
?>

21,886

社区成员

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

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