当前位置:Gxlcms > PHP教程 > 用Smarty生成静态文件的有关问题

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

时间:2021-07-01 10:21:17 帮助过:4人阅读

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

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

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

人气教程排行