首页  >  文章  >  后端开发  >  用Smarty生成 静态文件的有关问题

用Smarty生成 静态文件的有关问题

WBOY
WBOY原创
2016-06-13 13:50:441000浏览

用Smarty生成 静态文件的问题?
require( "../inc/fuction.php ");
require( "../inc/inc.php ");
require( "../inc/db.php ");
require   ( "../Smarty/Smarty.class.php ");

$id=$_GET[ 'id '];
if(isset($id)&&is_numeric($id))
{
  $db=new   F2MysqlClass($dbhost,   $dbuser,   $dbpw,   $dbname);
  $sql= "select   *   from   news   where   id= '$id ' ";
  $result=$db-> fetchArray($db-> query($sql));
  $tmp=new   Smarty;

  $tmp-> template_dir   =   "../smarty/templates/templates ";
$tmp-> compile_dir   =   "../smarty/templates/templates_c ";
$tmp-> config_dir   =   "../smarty/templates/config ";
$tmp-> cache_dir   =   "../smarty/templates/cache ";  

        if(!empty($result))
      {  
      $tmp-> assign(array(
        "title ",htmlspecialchars($result[ "title "]),
        "Name ",$result[ "author "]));  
      }  
  $tmp-> display( 'index.tpl ');
  $this_my_f=   ob_get_contents();   //此处关键
  ob_end_clean();
  $filename   =   "$id.html ";
  if(tohtmlfile_cjjer($filename,$this_my_f))
  echo   "生成成功   $filename ";
  else
  echo   "生成识别 ";  

}

//把生成文件的过程写出函数
function   tohtmlfile_cjjer($file_cjjer_name,$file_cjjer_content)
{
  if   (is_file   ($file_cjjer_name)){
    @unlink   ($file_cjjer_name);
  }
$cjjer_handle   =   fopen   ($file_cjjer_name, "w ");
  if   (!is_writable   ($file_cjjer_name)){
    return   false;
  }
  if   (!fwrite   ($cjjer_handle,$file_cjjer_content)){
    return   false;
  }  
fclose   ($cjjer_handle);   //关闭指针
return   $file_cjjer_name;
}

文件可以生成。但是生成的文件里的标签没替换?标签的地方显示的全是空白。什么问题?

------解决方案--------------------
怀疑赋值有问题

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn