亚洲国产日韩欧美在线a乱码,国产精品路线1路线2路线,亚洲视频一区,精品国产自,www狠狠,国产情侣激情在线视频免费看,亚洲成年网站在线观看

PHP中使用smarty生成靜態(tài)文件的實例

時間:2025-09-16 08:46:05 php語言

PHP中使用smarty生成靜態(tài)文件的實例

  導(dǎo)語: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)文件的實例】相關(guān)文章:

php簡單偽靜態(tài)實例03-07

php實現(xiàn)偽靜態(tài)的方法實例11-30

php靜態(tài)頁生成方法03-11

php使用html5實現(xiàn)多文件上傳實例02-27

PHP生成SiteMap文件的代碼03-05

PHP生成PDF文件withFPDF10-17

php生成靜態(tài)頁面的詳細(xì)教程12-29

php技術(shù)生成靜態(tài)頁面的方法12-25

如何生成靜態(tài)頁面的PHP類10-03