快速入门,smarty生成批量生成html
分类:计算机网络

n.php读取内容发送给smarty
<?php
include_once("config.php");
include_once("init.php");
$s->assign("title","所有的新闻分类");
$ID=$_GET["ID"]+0;
$sql="select * from artical where newsID=$ID";
$rs=$db->fetch($sql);
$s->assign("news",$rs["rec"][0]);//注意:$rs["rec"][0]是个数组
$s->display("news.html");
?>

<body bgcolor="#FFFFFF" background="image/bg.gif">
<?php include "header.php";?> <br>
<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#D8D8E8" bordercolordark="#D8D8E8">
  <tr>  
    <td height="20" width="27%" bgcolor="#d8dde9">版面:<?php
echo $chinesename;
?>(管理)</td>
    <td height="20" width="31%" bgcolor="#d8dde9">版主:<?php
while ($sql_row=mysql_fetch_array($sql_result))
{
echo "$sql_row[name]"." ";
}
# 选择出留言纪录;
$sql="select * from $board where slaveid=0";
$temp=mysql_query($sql);
$sum=mysql_num_rows($temp);
$totalpage=ceil($sum/$pagesize);
if ($sum==0) {
    $totalpage=1;
}
# 分页
if($page<1 or empty($page)){
    $page=1;
}
elseif ($page>$totalpage){
         $page=$totalpage;
}
$offset=($page-1)*$pagesize;
$sql="select * from $board where slaveid=0 order by id desc limit $offset,$pagesize";
$sql_result=mysql_query($sql);
?> </td>
    <td height="20" width="15%" bgcolor="#d8dde9">贴子总数:<?php echo $sum; ?></td>
    <td height="20" width="12%"><a href='javascript:post("<?php echo $board;?>")'><img src="image/newtopic.jpg" width="92" height="21" border="0" alt="发新贴子"></a></td>
    <td height="20" align="center" width="15%"><a href="<?php echo "$php_self?board=$board&page=$page";?>">刷新浏览</a></td>
  </tr>
</table>
<br>
<table width="100%" border="1" cellspacing="0" cellpadding="1" bordercolorlight="#CCCCCC" bordercolordark="#CCCCCC">
  <tr bgcolor="#995100" align="center">
    <td width="6%"><font color="#FFFFFF">回应</font></td>
    <td width="67%" bgcolor="#995100"><font color="#FFFFFF">主 题</font></td>
    <td width="20%"><font color="#FFFFFF">时 间</font></td>
    <td width="7%"><font color="#FFFFFF">人气</font></td>
  </tr>
  <tr bgcolor="#FFCC99">
    <td colspan="5" height="2"> </td>
  </tr>
  <?php
while ($sql_row=mysql_fetch_array($sql_result))
{
echo"<tr>";
echo"<td width="6%" bgcolor="#FFF5DD" align="center">";
if ($sql_row[renum]!=0)
      {
       echo "<font color="#FF0000">[+$sql_row[renum]]</font>";
      }
else
{
echo "[0]";
}
  echo"</td>";
  echo"<td bgcolor="#E8FDEE" width="56%"><font face="宋体"><a href='javascript:openwin("$board",$sql_row[id])' title="作者:$sql_row[writer] 大小:$sql_row[size]字节">$sql_row[title]</a></font></td>";
  echo"<td width="18%" bgcolor="#FFF5DD" align="center">$sql_row[writetime]</td>";
  echo"<td width="6%" bgcolor="#E8FDEE" align="center">$sql_row[hits]</td>";
  echo"</tr>";
}
?>
  <tr bgcolor="#FFCC99">
    <td colspan="5" align="center" height="2"> </td>
  </tr>
</table>
<div align="right">
<form method="post" action="<?php echo $php_self;?>">
    共<b><?php echo $totalpage;?></b>页 第<b><?php echo $page;?></b>页· <?php
if ($page!=1){
     $back=$page-1;
        echo"<a href="$php_self?board=$board&page=1">首页</a> <a href="$php_self?board=$board&page=$back">上一页</a>";
}
if ($page==1){
       echo"首页 上一页";
}
if($page!=$totalpage){
    $next=$page+1;
        echo" <a href="$php_self?board=$board&page=$next">下一页</a> <a href="$php_self?board=$board&page=$totalpage">尾页</a>";
}
if($page==$totalpage){
        echo" 下一页 尾页";
}
?>·转到第  
    <input type="text" name="page" size="2">
    页  
  </form>
</div>
<?php include "footer.php"?>
</body>
</html>
<?php
}
else {
    show_error(4);
}
?> 

 for(var j = 0 ; j < box_l ; j++){

例子:

function MakeHtmlFile($file_name, $c)

      if(!$fp = fopen($file_name, "wa"))
      {    
         echo "文件打开失败!";    
         return false;    
      }    
      if(!fwrite($fp, $c))
      {    
         echo "文件写入失败!";    
         fclose($fp);    
         return false;    
      }            
      fclose($fp);    
   }

<body background="image/bg.gif" bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="2" cellpadding="0">
  <tr>
    <td align="center"> </td>
  </tr>
  <tr>
    <td align="center"><a href="apply.php" target="main">注册用户</a></td>
  </tr>
  <tr>
    <td align="center"><font color="#666666">---------</font></td>
  </tr>
<?php
do
{
echo"<tr>";
echo"<td align="center"><a href="list.php?board=$sql_row[name]" target="main">$sql_row[chinesename]</a></td>";
echo"</tr>";
}while($sql_row=mysql_fetch_array($sql_result));
?>
<tr>
    <td align="center"><font color="#006666">---------</font></td>
  </tr>
  <tr>
    <td height="11">
      <script src=file/X86tree.js></script>
      <script language=javascript>
        img_t1="image/t1.gif";
        img_t2="image/t2.gif";
        tree=new TreeView(0,0,640,300);
        tree.AddImage(0,"image/dot.gif");
        tree.AddImage(1,"image/close.gif");
        tree.AddImage(2,"image/open.gif");

 

 

模板文件new.tpl
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url=;
<html xmlns="[url=;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title><{$news.titles}></title>
<link href="<{$docroot}>/css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" style="border:solid #CCCCCC 1px">
  <tr>
    <td height="25" colspan="6" align="center" bgcolor="#eeeeee"><strong><{$news.titles}></strong></td>
  </tr>
  <tr>
    <td width="74" height="25" align="right">作者:</td>
    <td width="220"><{$news.author}></td>
    <td width="40" align="right">时间:</td>
    <td width="134" align="left"><{$news.sj}></td>
    <td width="110" align="right">关键词:</td>
    <td width="220" align="left"><{$news.keyword}></td>
  </tr>
  <tr>
    <td height="25" align="right" >核心提示:</td>
    <td height="25" colspan="5" class="artical" style="border:double #FF0000 3px;"><{$news.sumary}></td>
  </tr>
  <tr>
    <td height="25" colspan="6" align="left" class="artical" style="padding:10px;"><{$news.contents}></td>
  </tr>
</table>
</body>
</html>

<frameset cols="125,*" rows="*" border="0" frameborder="0">  
  <frame src="left.php" name="left" scrolling="AUTO" frameborder="YES" bordercolor="#000000">
  <frame src="right.htm" name="main" scrolling="AUTO">
</frameset>
<noframes><body bgcolor="#FFFFFF">

 $sql ="select * from tbn where gx_object='$myname' and gx_mail='$mymail'";
 $result =mysql_query($sql); 
 if(mysql_num_rows($result)){
  mysql_free_result($result);
  alert('提示,你己提交留言,请不要重复提交!','');
 }
 $sql ="Insert into tbn(gx_content,gx_time,gx_tel,gx_mail,gx_object) value('$mybook','".date('y-m-d')."','$mytel','$mymail','$myname')";
 mysql_query($sql) or die(alert('你的留言中有非法数据!',''));
 alert('提示:留言成功',$_SERVER['HTTP_REFERER']);
  
 ?>

$s->display('add.html');

生成html文件函数写在smarty里面.

        tree.Show();
        doc2.Close();
        m1.Close();
</script>
    </td>
  </tr>
  <tr>
    <td align="center"> <b><font color="#006666">--------</font><br>
      <?php echo "$counter"?></b></td>
  </tr>
</table>
</body>
</html>
## list.php
<?php
require("func.php");
if(empty($board)){
    $board="computer";
}
$sql="select * from boardinfo where name='$board'";
$sql_result=mysql_query($sql);
$sql_row=mysql_fetch_array($sql_result);
$chinesename=$sql_row[chinesename];
setcookie ("jl_forum[chinesename]",$chinesename);
$sql="select name from user where slaveboard='$board'";
$sql_result=mysql_query($sql);
?>
<html>
<head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="css/index.css">
<script language="javascript">
function openwin(board,id){                window.open("read.php?board="+board+"&id="+id,"","height=460,width=600,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
function post(board){                window.open("post.php?board="+board,"","height=500,width=600,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
</script>
</head>

  document.getElementsByName("box_x[]")[j].checked = str;

<meta charset='utf-8' />

生成文件使用makeHtmlFile
<?php
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));
}
?>

        m1=new Nodes("m1",tree.ImageList,"论坛转向",0,2,"");
        m1.Add(new Node("站点首页",1,0,"<a href='' target='_top'>"));                                                              m1.Add(new Node("论坛首页",1,0,"<a href='right.htm' target='main'>"));
    tree.Add2(m1);

<?php
require_once("inc/connect.php");
 $myname =get_value('myname',post);
 $mymail =get_value('mymail',post);
 $mytel =get_value('mytel',post);
 $mybook =get_value('mycontent',post);
 //exit($mymail);
 if(strlen($myname)>100 || strlen($myname)<1){alert('用户长度1-100','');}
 if(!@preg_match("/w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*/",$mymail@w+(%5B-.%5Dw+).w+(%5B-.%5Dw+)/%22,$mymail)) || strlen($mymail)<6 ){alert('请输入正确的邮箱地址以便我们与你联系!','');}
 if(!@preg_match("/d{3}-d{8}|d{4}-d{7}/",$mytel)){alert(')%7Balert()请输入合法的电话如:0731-
*****','');}

##smarty
    //第一步移入smarty类
    require './libs/Smarty.class.php';
    //第二部实例化对象
    $s = new Smarty;
    //第三部初始化
    //模版目录初始化,模版存放目录
    $s->template_dir = './View';
    //编译目录
    $s->compile_dir = './View_c';
    $pdo = new PDO('mysql:host=localhost;dbname = pass;charset = utf8','root','');
    $stmt = $pdo->query('select * from stu');
    $res = $stmt->fetchAll(PDO::FETCH_ASSOC);

</body></noframes>
</html>
## left.php
<?php
$fp=fopen("file/counter.txt","r");
$counter=fgets($fp,8);
fclose($fp);
$counter=$counter+1;
$fp=fopen("file/counter.txt","w");
fputs($fp,$counter);
fclose($fp);
require("config.inc.php");
$sql="select * from boardinfo";
$sql_result=mysql_query($sql);
$sql_row=mysql_fetch_array($sql_result);
?>
<html>
<head>
<title>版面列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css/new.css" rel=stylesheet>
</head>

<body>
<table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" style="margin-top:20px; border:1px solid #9abcde;">
 <tr>
    <td height="25" colspan="3" background="skins/top_bg.gif"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
       <form id="form2" name="form2" method="post" action="?"> <tr>
          <td width="100%">你正在管理留言信息... </td>
          <td width="0%" align="right">
            <label></label><label></label></td>
        </tr></form>
      </table></td>
    </tr> <form id="form1" name="form1" method="post" action="menu_sava.php?action=allbook">
     <td width="4%"></tr>
 
    <?php
 
  $result =mysql_query("select * from tbn");
  $pagecount=1;
  $order=1;
  if(isset($_POST['key'])){
  $key=str_replace("'","*",$_POST['key']);
  }else if(isset($_GET['key'])){
  $key=str_replace("'","*",$_GET['key']);
  }else{
   $key='';
  }
  $total="select * from tbn";
  $sql="select * from tbn";
  if(!empty($key) && !is_null($key) && strlen($key)>2 && strlen($key)<50 ){
   $total.=" where gx_title like '%$key%' ";
 $sql.=" where gx_title like '%$key%' ";

<td><input type="text" name='title'></td>

## index.php
<html>
<head>
<title>论坛</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

第三步就是php代码处理留言的信息合法性了,

smarty 快速入门

        doc2=new Nodes("doc2",tree.ImageList,"论坛功能",0,2,"-");
            doc2.Add(new Node("帖子查询",1,0,"<a href='query.php' target='main'>"));
            doc2.Add(new Node("精华区域",1,0,"<a href='good.php' target='main'>"));
                doc2.Add(new Node("察看留言",1,0,"<a href='vmlogin.php' target='main'>"));
                doc2.Add(new Node("修改资料",1,0,"<a href='modify_l.php' target='main'>"));
                doc2.Add(new Node("察看资料",1,0,"<a href='userinfo.php' target='main'>"));
                doc2.Add(new Node("察看积分",1,0,"<a href='viewscore.php' target='main'>"));
                doc2.Add(new Node("论坛管理",1,0,"<a href='manage.htm' target='main'>"));
        tree.Add2(doc2);

  } 
  $result=mysql_query($total) or die('fail1'.mysql_error());
  $rs=mysql_fetch_array($result);
  $rdcount=mysql_num_rows($result);
  if($rdcount){
  $pagesize=15;
  $pagecount=($rdcount % $pagesize)?(int)($rdcount / $pagesize)+1:$rdcount/$pagesize;//统计总页面
  $page=isset($_GET['page'])?$_GET['page']:1;//取得当前页面
  $start=($page>=1 && $page<=$pagecount)?$start=$pagesize*($page-1):$start=1;//取得超始记录
  $order=isset($_GET['order'])?$_GET['order']:4;
   $sql.=" order by id desc limit $start,$pagesize";
   $resulte=mysql_query($sql) or die('fail'.mysql_error());
 while ($rs =mysql_fetch_array($resulte) ){
?>  <tr>
      <td height="25" colspan="3" align="left" valign="middle" background="images/main_bg.gif" class="td_heng" style="padding-right:5px;">
       
      <input type="checkbox" name="box_x[]" id="box_x[]" value="<?php echo $rs[0];?>" />
     
      标题:<?php echo $rs['gx_title']?>
      作者:<?php echo $rs['gx_object']?>
      电话:<?php echo $rs['gx_tel']?>
      时间:<?php echo $rs['gx_time']?>
      邮箱:<?php echo $rs['gx_mail']?></td>
  
    <tr onMouseOver="this.style.background='#d7ebff'" onMouseOut="this.style.background='#ffffff'">
      <td height="27" colspan="2" align="left" valign="middle" class="td_heng" style="padding:15px;">
    <?php echo $rs['gx_content']?>      </td>
      <td width="7%" align="center" valign="bottom" class="td_heng"><a href="menu_sava.php?action=delguest&id=<?php echo $rs[0];?>" onclick="javascript:return confirm('确认删除?删除后无法恢复','','');">删除</a></td>
    </tr>
    <tr>
     <td height="32" colspan="3"> </td>
   </tr>
   <?php
   }
   }
   ?>
  
   <tr>
    <td height="32" colspan="3" background="skins/top_bg.gif"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="34%"><input type="button" onclick="javascript:all_(true);" name="Submit" value="全选" />
             
            <input type="button"  onclick="all_(false);" name="Submit" value="反选" />
             
            <input type="submit" onclick="javascript:return confirm('确认提醒:删除后无法还原!','','');" value='删除所选项' /></td>
          <td width="66%" align="right" style="word-spacing:5px;">
    <?php
    $url ="?key=".rawurlencode($key)."&orderby=$order&page=";
    pagelist(@$page,$pagecount,$rdcount,$url,@$pagesize);
    ?></td>
        </tr>
      </table></td>
  </tr> </form>
</table>
</body>
</html>

 

<body bgcolor="#FFFFFF" background="image/bg.gif">
<?php include "header.php";?> <br>
<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
  <tr>  
    <td height="22" width="23%" bgcolor="#eeeeee">版面:<?php
echo $chinesename;
?></td>
    <td height="22" width="41%" bgcolor="#eeeeee">版主:<?php
while ($sql_row=mysql_fetch_array($sql_result))
{
echo "$sql_row[name]"." ";
}
# 选择出留言纪录;
$sql="select * from $board where slaveid=0";
$temp=mysql_query($sql);
$sum=mysql_num_rows($temp);
$totalpage=ceil($sum/$pagesize);
if ($sum==0) {
    $totalpage=1;
}
# 分页
if($page<1 or empty($page)){
    $page=1;
}
elseif ($page>$totalpage){
         $page=$totalpage;
}
$offset=($page-1)*$pagesize;
$sql="select * from $board where slaveid=0 order by id desc limit $offset,$pagesize";
$sql_result=mysql_query($sql);
?> </td>
    <td height="22" width="13%" bgcolor="#eeeeee">贴子总数:<?php echo $sum; ?></td>
    <td height="22" width="12%"><a href='javascript:post("<?php echo $board;?>")'><img src="image/newtopic.jpg" width="93" height="21" border="0" alt="发新贴子"></a></td>
    <td height="22" width="11%">  
      <div align="center"><a href="<?php echo "$php_self?board=$board&page=$page";?>">刷新浏览</a></div>
    </td>
  </tr>
</table>
<br>
<table width="100%" border="1" cellspacing="0" cellpadding="1" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF">
  <tr bgcolor="#995100" align="center">
    <td width="6%"><font color="#FFFFFF">回应</font></td>
    <td width="67%" bgcolor="#995100"><font color="#FFFFFF">主 题</font></td>
    <td width="20%"><font color="#FFFFFF">时 间</font></td>
    <td width="7%"><font color="#FFFFFF">人气</font></td>
  </tr>
  <tr bgcolor="#FFCC99">
    <td colspan="5" height="2"> </td>
  </tr>
  <?php
while ($sql_row=mysql_fetch_array($sql_result))
{
echo"<tr>";
echo"<td width="6%" bgcolor="#FFF5DD" align="center">";
if ($sql_row[renum]!=0)
      {
       echo "<font color="#FF0000">[+$sql_row[renum]]</font>";
      }
else
{
echo "[0]";
}
  echo"</td>";
  echo"<td bgcolor="#E8FDEE" width="56%"><font face="宋体"><a href='javascript:openwin("$board",$sql_row[id])' title="作者:$sql_row[writer] 大小:$sql_row[size]字节">$sql_row[title]</a></font></td>";
  echo"<td width="18%" bgcolor="#FFF5DD" align="center">$sql_row[writetime]</td>";
  echo"<td width="6%" bgcolor="#E8FDEE" align="center">$sql_row[hits]</td>";
  echo"</tr>";
}
?>
  <tr bgcolor="#FFCC99">
    <td colspan="5" align="center" height="2"> </td>
  </tr>
</table>
<div align="right">
<form method="post" action="<?php echo $php_self;?>">
    共<b><?php echo $totalpage;?></b>页 第<b><?php echo $page;?></b>页·<?php
if ($page!=1){
     $back=$page-1;
        echo"<a href="$php_self?board=$board&page=1">首页</a> <a href="$php_self?board=$board&page=$back">上一页</a>";
}
if ($page==1){
       echo"首页 上一页";
}
if($page!=$totalpage){
    $next=$page+1;
        echo" <a href="$php_self?board=$board&page=$next">下一页</a> <a href="$php_self?board=$board&page=$totalpage">尾页</a>";
}
if($page==$totalpage){
        echo" 下一页 尾页";
}
?>·  
    <input type="submit" name="goto" value="转到">
    <input type="text" name="page" size="2">
    页  
  </form>
</div>
<?php include "footer.php";?>
</body>
</html>
## login.php
<?php
require "func.php";
if ($name==$admin_name and $password==$admin_password) {
    setcookie ("jl_admin[name]",$name);
    setcookie ("jl_admin[password]",$name);
    redirect2("admin.php");
}
else {
    show_error(1);
}
?>
## manage.php
<?php
require "func.php";
if (check_admin_password()) {
    switch ($job){
        case "setgood":
            set_good($jl_forum[board],$id);
            break;
        case "setnogood":
            set_no_good($jl_forum[board],$id);
            break;
        case "delete":
            del_doc($jl_forum[board],$id);
            break;
    }
echo "<h2>操作成功!</h2><br>";
?>
<html><head><title>o,k</title></head><body>
<form method="POST">
      <input type="button" value=" 关 闭 " name="B1" onclick="window.close()">
</form>
</body>
</html>
<?php
}
else {
    show_error(1);
}
?>
## manage_list.php
<?php
require("func.php");
if (check_admin_password()) {
$board=$jl_forum[board];
$sql="select * from boardinfo where name='$board'";
$sql_result=mysql_query($sql);
$sql_row=mysql_fetch_array($sql_result);
$chinesename=$sql_row[chinesename];
setcookie ("jl_forum[chinesename]",$chinesename);
$sql="select name from user where slaveboard='$board'";
$sql_result=mysql_query($sql);
?>
<html>
<head>
<title>List</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="css/index.css">
<script language="javascript">
function openwin(board,id){                window.open("manage_read.php?board="+board+"&id="+id,"","height=460,width=600,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
function post(board){                window.open("post.php?board="+board,"","height=500,width=600,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
</script>
</head>

 

    //建立 view文件存放改变网页 view_c转换文件

<style type="text/css">
<!--
.STYLE1 {color: #000000}
.STYLE2 {color: #0000FF}
-->
</style>
<script>
<!--
function all_(str){

{foreach $res as $v}

 }

<td><?= $v['url']?></td>

<?php
 include("../inc/connect.php"); 
  ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="style/admin.css" rel="stylesheet" type="text/css" />

</tr>

 var box_l = document.getElementsByName("box_x[]").length;

 

}
--></script>
</head>

 

注:原创文章转载请注明:www.111cn.net

<tr>

最四步就是显示留言了.

缓存页面

    //第四步分配变量
    $s->assign('title','smart的一个模版');
    $s->assing('name','mingzi');
    $s->assing('res','$res');
    //第五步解析模版
     $s->display('2.html');

$res = $stmt->fetchAll(PDO::FETCH_ASSOC);

<table border='0' width='400'> 

</style>

{/block}

<tr>

 

$s->assign('title','新闻管理系统???????????');

h3{font-family:微软雅黑;}

<td><?= $v['price']?></td>

 

<td><?= $v['title']?></td>

<h2>新闻管理系统</h2>

<tr>

<td><?= $v['id']?></td>

compile_dir  编译目录

<tr>

    {/foreach}
    {literal}

3.初始化参数

2.实例化smarty对象

 

定义:一个开源的模板引擎

<a href="./add.php">发布新闻</a>

<style type="text/css">

require './libs/Smarty.class.php';

<body>

//第一步移入smarty类

{/foreach}

<input type="submit" value='添加' />   

www.smarty.net

 

<td align='right'>标题:</td>

 

<td><input type="text" name='keywords'></td>

 

{/block}

<td><textarea name="content" id="" cols="30" rows="5" width='300px' height='200px' style='resize:none'></textarea></td>

<input type="reset" value='重置' />

 

$s->assign('res',$res);

 

</head>

 

<center>

index.html

 

</tr>

下载

$pdo = new PDO('mysql:host=localhost;dbname=pass;charset=utf8','root','');

 

</tr>

将网站的数据和网站的界面实现分离(php和html代码)

<html lang="en">

{extends file='index.html'}

</table>

<td colspan='3' align='center'>

</table>

 

模板引擎是为了使用户界面与业务数据分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的HTML文档。

smarty

{block name='title'}

//var_dump($res);

{include file='menu.html'}

<meta charset="UTF-8">

</tr>

 

$s = new Smarty;

<table border='1' width='880'>

    {/literal}
    {include file='menu.html'}  引入
    
    {block name ='content'}s
    mysqli 
    //引入文件/
    define('HOST','localhost');
    define('USER','root');
    define('PWD','');
    define('DBNAME','pass');
    define('UTF','utf8');

{/literal}

$stmt = $pdo->query('select * from news');

$s->template_dir = './View';

$s->compile_dir = './View_c';

 

</form>

功能

 

 

{literal}

// $s->assign('name','什么呢????');

忽略smarty解析     {literal} {/literal}

 

 

{block name='title'}

使用

</body>

<head>

</center>

<!DOCTYPE html>

 

<title>新闻管理系统</title>

<style type="text/css">

<tr>

1.引入smarty类库

 

 

<h3>发布新闻</h3>

template_dir  模板存放目录

 

<form action="action.php?action=add" method='post'>

<td><input type="text" name='author'></td>

table,td{font-family:微软雅黑;text-align:center;}

<tr>

    $link = @mysqli_connect(HOST,USER,PWD) or die('连接失败')
    mysqli_select_db($link,DBNAME);  //选择数据库
    mysqli_set_charset($link,UTF);    //字符集
    $sql = 'select * from news order by id');
    $result = mysqli_query($link,$sql);
    //查询结果辅助函数
    mysqli_num_rows($result)>0
    mysqli_fetch_assoc($result)   得到关联数组
    mysqli_close($link)  //关闭数据库                

</style>

     2.html更改
    {$ title} 
    {$name}
    {foreach $res as $v}
        {$v['id']}
        {$v['name']}

{/block}

注释    {* 这是注释的内容*}

add.html

//第四步 分配变量

</tr>

 

 

 

<td align='right'>关键字:</td>

<title>新闻添加页面</title>

<a href="./index.php">浏览新闻</a>  | 

<tr>

 

{block name='content'}

</td>

<th>新闻ID</th><th>新闻标题</th><th>新闻关键字</th><th>作者</th><th>新闻内容</th><th>操作</th>

 

menu.html

//第三步初始化

 

{/block}

 

<hr width='800px' />

<td align='right'>作者:</td>

5.解析模板

body{ font-family:微软雅黑;}

<h3>浏览新闻</h3>

</html>

{block name='content'}

 

</tr>

<td align='right'>内容:</td>

//第五步 解析模板

 

4.分配变量

//第二步实例化对象

</tr>

本文由美高梅网址发布于计算机网络,转载请注明出处:快速入门,smarty生成批量生成html

上一篇:过滤html标签多种方法,PHP将HTML转换成文本一些方 下一篇:php中timezone时区设置方法,php设置时区方法介绍
猜你喜欢
热门排行
精彩图文