smarty学习1

  php里的smarty是个不错的模版,是个好东西来的,最近项目要用到,找了本packet publishing出的
smarty of php的书来看,很薄,不错的书,现将主要内容等笔记之

1 安装
    下载后的 smarty 解压缩后,将lib目录放到当前php项目的根目录下就可以了,然后还要
建立templates目录存放模版,template_c目录用来存放模版产生的文件

2  建立tpl模版
   在templates目录下建立index.tpl模版,假设是用列表的形式列出数据库内容

 {foreach item=huojiang from=$huojiangs}
              <tr>
                <td width="60%">{$huojiang.nickname}</td>
                <td align="center" width="40%">{$huojiang.score}</td>
              </tr>
   {/foreach}
看到了吧,一个{foreach}就OK了,接下来,先看调用文件index.php
<?

require("libs/Smarty.class.php");
$smarty = new Smarty();

//.....数据库连接代码


//设置一个数组
$huojiangs=array();

     $jifensocre= mysql_query("..............................................");
      while ($arr=mysql_fetch_assoc($jifensocre)) 
               {
       $huojiangs[]=$arr;

    }
$smarty->assign("huojiangs",$huojiangs);        //assign
$smarty->display("index1.tpl");              //compile and render the output  
     ?>
$smarty->assign("huojiangs",$huojiangs);   这句中,把数组赋值给huojiangs了,
然后在模版里,用
 {foreach item=huojiang from=$huojiangs}
这里进行调用


posted on 2007-04-29 14:42 jackyrong的世界 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/jackyrong/archive/2007/04/29/732272.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值