smarty生成静态

smarty生成静态很简单的

利用自带的$smarty->fetch();我个人感觉没有必要生成静态,打开$smarty->caching=2缓存的话,在cache文件夹已经生成了,静态的文件,

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
// 对将要输出的内容进行处理


echo $output;

代码如下:

<?php
include_once 'model/T_SecondHouseA_action.php';
include_once 'model/T_TypeA_action.php';
include_once 'model/T_NewsA_action.php';
include_once 'model/T_User.php';
$newsAction = new T_NewsA();
$typeAction=new T_TypeA();
$agent=new T_UserA();
$secondHouse=new T_SecondHouseA();
$typeArr = $typeAction->T_TypeA_selectKV();
//二手房评估
$zixun=$agent->T_getZiXun();
//购房指南
$news = $newsAction->T_NewsA_getNewsByTypeId($typeArr['购房指南'],8,'Id desc');
//经纪人名录
$agent=new T_UserA();
$agentName=$agent->T_UserA_getAgent();
$shopName=$agent->T_UserA_getShop();
require 'libs/Smarty.class.php';
$smarty = new Smarty;
//接收的参数
$source=(int)$_GET['source'];//来源:1:个人2:中介3:门店
$zone=(int)$_GET['zone'];//区域
if(!empty($_GET['price'])){//price是上面搜索的
	$priceArr=explode('-',$_GET['price']);
	$minprice=(int)$priceArr[0];
	$maxprice=(int)$priceArr[1];
}else{
$minprice=(int)$_GET['minprice'];
$maxprice=(int)$_GET['maxprice'];
}
$department=(int)$_GET['department'];//户型,1:一室,2:2室,6:5室以上
$type=(int)$_GET['type'];//房型:1:住宅2:
// echo urldecode($name);
$name=mb_convert_encoding(trim($_GET['name']),'GBK','utf-8');
if(!empty($name)){//name是上面的搜索
	$name=$name ? Mssql::get_magic(trim($name)) : 0;//楼盘名称
}else{
	$name=0;
}
$minarea=(int)$_GET['minarea'];//面积范围小
$maxarea=(int)$_GET['maxarea'];//面积范围大
$pic=(int)$_GET['pic'];//图片房源,有图片为1
$top=(int)$_GET['top'];//推荐房源,推荐为1
$z=(int)$_GET['z'];//按照面积排序,1:为升序,2:为降序
$single=(int)$_GET['single'];//按照单价排序,1:为升序,2:为降序
$total=(int)$_GET['total'];//按照单价排序,1:为升序,2:为降序
$time=(int)$_GET['time'];//按照时间排序,1:为升序,2:为降序
$pagesize=$_GET['pagesize'] ? (int)$_GET['pagesize'] : 25;
$pageindex=$_GET['pageindex'] ? (int)$_GET['pageindex'] : 1;
//商圈参数
if(isset($_GET['business'])){
	if(!empty($_GET['business'])){
	$business=iconv('utf-8','gb2312',trim($_GET['business']));
	$business=Mssql::get_magic($business);
	}else{
		$business=0;
	}
}
// echo $business;
// die;
/*echo '$source:'.$source.'<br />';
echo '$zone:'.$zone.'<br />';
echo '$_GET[price]:'.$_GET['price'].'<br />';
echo '$department:'.$department.'<br />';
echo '$type:'.$type.'<br />';
echo '$name:'.$name.'<br />';
echo '$minprice:'.$minprice.'<br />';
echo '$maxprice:'.$maxprice.'<br />';
echo '$minarea:'.$minarea.'<br />';
echo '$maxarea:'.$maxarea.'<br />';
echo '$pic:'.$pic.'<br />';
echo '$top:'.$top.'<br />';
echo '$z:'.$z.'<br />';
echo '$single:'.$single.'<br />';
echo '$total:'.$total.'<br />';
echo '$time:'.$time.'<br />';
echo '$pagesize:'.$pagesize.'<br />';
echo '$pageindex:'.$pageindex.'<br />';
echo '$business:'.$business.'<br />';
die;
*/


$arrar=$secondHouse->T_SecondHouseA_Search($source,$zone,$minprice,$maxprice,$minarea,$maxarea,$department,$type,$name,$pic,$top,$z,$single,$total,$time,$pagesize,$pageindex,$business);
 // print_r($arrar);
// echo '<br />';
 // die;

$pageCount=$secondHouse->T_SecondHouseA_SearchCount($source,$zone,$minprice,$maxprice,$minarea,$maxarea,$department,$type,$name,$pic,$top,$business);

$totalpage=ceil($pageCount/$pagesize);

if($source==0){$source='';}
if($zone==0){$zone='';}
if($price==0){$price='';}
if($department==0){$department='';}
if($type==0){$type='';}
if($name===0){$name='';}
if($minprice==0){$minprice='';}
if($maxprice==0){$maxprice='';}
if($minarea==0){$minarea='';}
if($maxarea==0){$maxarea='';}
if($pic==0){$pic='';}
if($top==0){$top='';}
if($z==0){$z='';}
if($single==0){$single='';}
if($total==0){$total='';}
if($time==0){$time='';}
if($business===0){$business='';}

$numPage=F::page(10,$totalpage,$source,$zone,$price,$minprice,$maxprice,$minarea,$maxarea,$department,$type,$name,$pic,$top,$z,$single,$total,$time,$pagesize,$pageindex,$business);
if($pageindex<2){
	$prePage=1;
}else{
	$prePage=$pageindex-1;
}
if($pageindex+1>$totalpage){
	$nextPage=$totalpage;
}else{
	$nextPage=$pageindex+1;
}
//统计下载次数
$str=file_get_contents('configs/count.txt');
$hits=unserialize($str);
//相关配置
$smarty->compile_check = true;
$smarty->debugging = false;
//购房指南
$smarty->assign('news',$news);
//经纪人名录
$smarty->assign('agentName',$agentName);
$smarty->assign('shopName',$shopName);
//搜索出来的变量
$smarty->assign('arra',$arrar);
$smarty->assign('size',$pageCount);
$smarty->assign('totalpage',$totalpage);
$smarty->assign('prePage',$prePage);
$smarty->assign('nextPage',$nextPage);
// echo $nextPage;
// echo '<br />';
// echo $totalpage;
// die;
//分页变量

$smarty->assign('numPage',$numPage);
$smarty->assign('name',$name);
//
$smarty->assign('zixun',$zixun);
//
$smarty->assign('hits1',$hits[0][1]);
$smarty->assign('hits2',$hits[1][1]);
$smarty->assign('hits3',$hits[2][1]);
$content=$smarty->fetch('list.html');
$fp=fopen('list.html','wb');
fwrite($fp,$content);
fclose($fp);
die('静态文件生成成功');
// $smarty->display('list.html');

?>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值