PHP中使用smarty生成靜態(tài)文件的實(shí)例
導(dǎo)語(yǔ):PHP中使用smarty生成靜態(tài)文件,并不是想象中那么容易,下面是百分網(wǎng)小編為大家整理了一下PHP中使用smarty生成靜態(tài)文件的實(shí)例,希望對(duì)你能有所幫助。
首先先要把需要靜態(tài)化的內(nèi)容填充到模版中去
代碼如下:
#eg.這個(gè)是靜態(tài)化首頁(yè)的
function staticIndex(){
$newslist = $article->getArticles(null,54,'DESC',1,6,false,1,2,'',0,0,1);
if($newslist){
foreach($newslist as $k=>$v){
$newslist[$k]['title_all'] = $v['title'];
$newslist[$k]['title'] = cutstr($v['title'],36,'…');
}
$smarty->assign('newslist',$newslist);
}
$content = '';
$content = $smarty->fetch('index.html',true);/pic/div>
$static_name = ROOT_PATH.'index.html';/pic/div>
fopen($static_name,'a');/pic/div>
@file_put_contents($static_name,$content);/pic/div>
return true;
}
/pic/div>
function staticContent(){/pic/div>
$ids = array();/pic/div>
$ids = $this->getListIds();/pic/div>
foreach($ids as $k=>$value){
/pic/div>
if(!file_exists(ROOT_PATH.'demo/')){/pic/div>
mkdir(ROOT_PATH.'demo/');
}
if(!file_exists(ROOT_PATH.'demo/'.$value['catid'])){/pic/div>
mkdir(ROOT_PATH.'demo/'.$value['catid']);
}
$html_content = $this->getDemoContent($value['demoid']);
$static_name = ROOT_PATH.'demo/'.$value['catid'].'/'.$value['demoid'].'.html';
fopen($static_name,'a');
@file_put_contents($static_name,$html_content);
}
return true;
}
/pic/div>
function getListIds(){
$sql = "select * from {$this->tablepre}demo order by demoid asc";
$rs = $this->db->getAll($sql);
if($rs){
return $rs;
}else{
return false;
}
}
/pic/div>
function getDemoContent($id){
global $smarty,$view_templates,$admin_templates;
loadModel(array('demo'));
$demo = new demo();
$content = '';
$smarty->template_dir = ROOT_PATH.$view_templates;
$getMobanOne = $this->getMobanDetail($id);
$mobandetail = $demo->MobanList($id);
foreach($mobandetail as $k=>$v){
$smarty->assign($k,$v);
}
$this->catid = $getMobanOne['catid'];
$smarty->assign('pre_title',$mobandetail['membername']);
$smarty->assign('mobandetail',$mobandetail);
$content = $smarty->fetch('demo_show.html',true);
$smarty->template_dir = ROOT_PATH.$view_templates;
return $content;
}
【PHP中使用smarty生成靜態(tài)文件的實(shí)例】相關(guān)文章:
php簡(jiǎn)單偽靜態(tài)實(shí)例03-07
php實(shí)現(xiàn)偽靜態(tài)的方法實(shí)例11-30
php靜態(tài)頁(yè)生成方法03-11
php使用html5實(shí)現(xiàn)多文件上傳實(shí)例02-27
PHP生成SiteMap文件的代碼03-05
PHP生成PDF文件withFPDF10-17
php生成靜態(tài)頁(yè)面的詳細(xì)教程12-29