After some groping, finally found a way to write to everyone pointing out:
First add such a method to the Smarty class in smartt.class.php:
PHP Code:
Parameter one: The HTML file save path, Parameter 2: Write the content
function Makehtmlfile ($file _name, $c)
{
if (! $fp = fopen ($file _name, "WA"))
{
echo "File open failed! ";
return false;
}
if (!fwrite ($FP, $c))
{
echo "File write Failed! ";
Fclose ($FP);
return false;
}
Fclose ($FP);
}
Question: All my articles are called News.tpl this template, then how to batch generation it?
Let's see news.php first.
PHP Code:
Include_once ("config.php");
Include_once ("init.php");
$s->assign ("title", "All News categories");
$ID =$_get["ID"]+0;
$sql = "SELECT * from artical where newsid= $ID";
$rs = $db->fetch ($sql);
$s->assign ("news", $rs ["Rec"][0]);//Note: $rs ["Rec"][0] is a number of groups
$s->display ("news.html");
?>
The whole template variable is only $news, so what's the benefit of writing it? I can read the contents as an array
So how exactly is the build:
Look at the following code:
It's simple.
PHP Code:
Include_once ("config.php");
Include_once ("init.php");
$sql = "SELECT * from artical";
$rs = $db->fetch ($sql);
foreach ($rs ["Rec"] as $k + = $v)
{
$s->assign ("news", $v);
$s->makehtmlfile ("./news/news_". $v [0]. ". HTML ", $s->fetch (" news.html ", NULL, NULL, FALSE));
}
?>
It's a simple move!
PHP Code:
<{$news .titles}>
| <{$news .titles}> |
| Author: |
<{$news .author}> |
Time: |
<{$news .sj}> |
Keywords: |
<{$news .keyword}> |
| Core tips: |
<{$news .sumary}> |
| <{$news .contents}> |
Summary: The main use of the Smarty fetch method, and file read and write operations
http://www.bkjia.com/PHPjc/508318.html www.bkjia.com true http://www.bkjia.com/PHPjc/508318.html techarticle after some groping, finally find the method, write to everybody pointing out: First in smartt.class.php to add such a method for the Smarty class: PHP Code://Parameter one: HTML file Save ...