PHP中使用smarty生成靜態(tài)文件的實例
導語:PHP中使用smarty生成靜態(tài)文件,并不是想象中那么容易,下面是百分網(wǎng)小編為大家整理了一下PHP中使用smarty生成靜態(tài)文件的實例,希望對你能有所幫助。
首先先要把需要靜態(tài)化的內(nèi)容填充到模版中去
代碼如下:
#eg.這個是靜態(tài)化首頁的
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)文件的實例】相關文章:
php簡單偽靜態(tài)實例03-07
php靜態(tài)頁生成方法03-11
php使用html5實現(xiàn)多文件上傳實例02-27
PHP生成SiteMap文件的代碼03-05
PHP生成PDF文件withFPDF10-17
php生成靜態(tài)頁面的詳細教程12-29
php技術生成靜態(tài)頁面的方法12-25
如何生成靜態(tài)頁面的PHP類10-03