After some exploration, I finally found a method and wrote it out for you to give pointers: first in smartt. class. in php, add the following method to the Smarty class: PHP code: parameter 1: html file storage path, parameter 2: written content functionMakeHtmlFile ($ file_name, $ c) {& nbsp; & nbsp; if (! $ Fpfopen ($ file_name, after some exploration, I finally found a method. let's give you some advice:
First, add the following method to the Smarty class in smartt. class. php:
PHP code:
// Parameter 1: html file storage path; parameter 2: written content
Function MakeHtmlFile ($ file_name, $ c)
{
If (! $ Fp = fopen ($ file_name, "wa "))
{
Echo "file opening failed! ";
Return false;
}
If (! Fwrite ($ fp, $ c ))
{
Echo "file writing failed! ";
Fclose ($ fp );
Return false;
}
Fclose ($ fp );
}
Q: all my articles call the news. tpl template. how can I generate them in batches?
Let's take a look at news. php.
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 an array
$ S-> display ("news.html ");
?>
The entire template variable is only $ news. What are the advantages of this writing? I can read content in arrays.
Then how to generate:
See the following code:
Very 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 _". $ v [0]. ". html ", $ s-> fetch (" news.html ", null, null, false ));
}
?>
It's easy!
PHP code:
<{$ News. titles}>
<{$ News. titles}> |
Author: |
<{$ News. author}> |
Time: |
<{$ News. sj}> |
Keywords: |
<{$ News. keyWord}> |
Core tips: |
<{$ News. sumary}> |
<{$ News. contents}> |
Summary: The smarty fetch method and file read/write operations are mainly used.