Home  >  Article  >  Backend Development  >  用Smarty生成 静态文件的有关问题

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

WBOY
WBOYOriginal
2016-06-13 13:50:441000browse

用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;
}

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

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn