smarty生成静态页问题,值得思考? 本帖最后由 bing15 于 2013-03-06 16:36:02 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 php 怎么做,smarty 还是一样的没啥区别 把生成的内容5个页要做成一定格式的页面,应该需要在smarty中专门写个方法 http://bbs.php100.com/read-htm-tid-308311.html 我已经做成功了,分享代码给大家,希望以后有人用得着。public function tplmakelist(&$tpl){ $pageSize=1; $_field=array('a.id','a.title','b.typedir','b.templist','b.keywords','b.description'); $this->_tables=array(DB_FREFIX.'article a',DB_FREFIX.'article_category b'); $data=parent::select($_field,array('where'=>array("a.catid=b.id AND b.id={$this->_R['typeid']}"))); $total=count($data);//分类下的所有文章 $pageTotal=ceil($total/$pageSize);//共有多少个分页 $tpl->template_dir=SMARTY_TEMPLATE_DIR; for ($i=1;$i<=$pageTotal;$i++){//生成的页数 $file_name=ROOT_PATH.$data[0]->typedir."/list_{$this->_R['typeid']}_$i.html"; $this->_tables=array(DB_FREFIX.'article a',DB_FREFIX.'article_category b'); $firstPage = ($i-1)*$pageSize; $datas=parent::select($_field,array('where'=>array("a.catid=b.id AND b.id={$this->_R['typeid']}"),'limit'=>"$firstPage,$pageSize")); $tpl->assign('findlist',$data[0]); $tpl->assign('pagelist',$datas); $content=$tpl->fetch($data[0]->templist); $this->MakeHtmlFile($file_name, $content); } } private function MakeHtmlFile($file_name, $content) { //目录不存在就创建 if (!file_exists (dirname($file_name))) { if (!@mkdir (dirname($file_name), 0777)) { die($file_name."目录创建失败!"); } } if(!$fp = fopen($file_name, "w")){ echo "文件打开失败!"; return false; } if(!fwrite($fp, $content)){ echo "文件写入失败!"; fclose($fp); return false; } fclose($fp); chmod($file_name,0666); }{foreach from=$pagelist item=list}<div><a href="">{$list->title}</a></div>{/foreach}以后如果你要用的话,把数据库的字段换下,连接数据库根据你自己的引擎来写,当然还有待扩展,刚写完的。 [分享]最新PHP中文手册 2008-12-23编译 phpmyadmin导入sql时出错? lxblog添加新功能需要更改哪些文件? zend studio 5.5 怪! php怎么去的第一个字的笔画数 模拟post失败 为什么? 关于joomla的问题 thinkphp做的网站中如何添加留言或论坛功能 谁有最土团购的短信接口? 请问有哪些开源PHP项目能够实现图形化展示。 新手请求帮助,求解决解决 求大神帮忙把一段php代码转成asp的
$pageSize=1;
$_field=array('a.id','a.title','b.typedir','b.templist','b.keywords','b.description');
$this->_tables=array(DB_FREFIX.'article a',DB_FREFIX.'article_category b');
$data=parent::select($_field,array('where'=>array("a.catid=b.id AND b.id={$this->_R['typeid']}")));
$total=count($data);//分类下的所有文章
$pageTotal=ceil($total/$pageSize);//共有多少个分页
$tpl->template_dir=SMARTY_TEMPLATE_DIR;
for ($i=1;$i<=$pageTotal;$i++){//生成的页数
$file_name=ROOT_PATH.$data[0]->typedir."/list_{$this->_R['typeid']}_$i.html";
$this->_tables=array(DB_FREFIX.'article a',DB_FREFIX.'article_category b');
$firstPage = ($i-1)*$pageSize;
$datas=parent::select($_field,array('where'=>array("a.catid=b.id AND b.id={$this->_R['typeid']}"),'limit'=>"$firstPage,$pageSize"));
$tpl->assign('findlist',$data[0]);
$tpl->assign('pagelist',$datas);
$content=$tpl->fetch($data[0]->templist);
$this->MakeHtmlFile($file_name, $content);
} }
private function MakeHtmlFile($file_name, $content)
{ //目录不存在就创建
if (!file_exists (dirname($file_name))) {
if (!@mkdir (dirname($file_name), 0777)) {
die($file_name."目录创建失败!");
}
}
if(!$fp = fopen($file_name, "w")){
echo "文件打开失败!";
return false;
}
if(!fwrite($fp, $content)){
echo "文件写入失败!";
fclose($fp);
return false;
}
fclose($fp);
chmod($file_name,0666);
}{foreach from=$pagelist item=list}
<div><a href="">{$list->title}</a></div>
{/foreach}以后如果你要用的话,把数据库的字段换下,连接数据库根据你自己的引擎来写,当然还有待扩展,刚写完的。