教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 smarty 基础入门

smarty 基础入门

发布时间:2023-05-11   编辑:jiaochengji.com
教程集为您提供smarty 基础入门等资源,欢迎您收藏本站,我们将为您提供最新的smarty 基础入门资源

PHP文件原代码:
<?php
include_once("./comm/Smarty.class.php"); //包含smarty类文件
define("NUM", 5); //定义每次显示的新闻条数
$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->templates_dir = "./templates"; //设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->cache_dir = "./cache"; //设置缓存目录
$smarty->cache_lifetime = 60 * 60 * 24; //设置缓存时间
$smarty->caching = false; //这里是调试时设为false,发布时请使用true
$smarty->left_delimiter = "<{"; //设置左边界符
$smarty->right_delimiter = "}>"; //设置右边界符
$db=mysql_connect('localhost','root','123456');
mysql_select_db('liu',$db);
$sql="select id,title from lyb";
mysql_query("set names gb2312");
$result=mysql_query($sql,$db);
while($row=mysql_fetch_array($result)){
$array[]=array("id"=>$row['id'],
     "title"=>$row['title']);

}
mysql_close();
$smarty->assign('new',$array);
$smarty->display('3.html');
?>
3.html
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#B9E9FF">
<tr>
<td height="115" width="10"></td>
<td valign="top" width="295" bgcolor="#B9E9FF">
<{section name=loop loop=$new}>
<{$new[loop].id}>
<{$new[loop].title}><br>
<{/section}>
</td>
</tr>
</table>
现在说明下:3.php中的东西.
我是用过程写的方面大家看下啊!
$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->templates_dir = "./templates"; //设置模板目录 这个必须真实存在(HTML文件在这里)
$smarty->compile_dir = "./templates_c"; //设置编译目录 这个必须真实存在(编译的目录)

$smarty->cache_dir = "./cache"; //设置缓存目录
$smarty->cache_lifetime = 60 * 60 * 24; //设置缓存时间
$smarty->caching = false; //这里是调试时设为false,发布时请使用true
$smarty->left_delimiter = "<{"; //设置左边界符
$smarty->right_delimiter = "}>"; //设置右边界符
$smarty->assign('new',$array); //这个是new在html中section LOOP值
$smarty->display('3.html');    //这个是哪个HTML文件.
在html中.<{section name=loop loop=$new}>
<{$new[loop].id}>
<{$new[loop].title}><br>
<{/section}>

您可能感兴趣的文章:
有关smarty的基本设置
smarty 模板if else使用实例与入门教程
零基础php自学要多久
php smarty 基础
适合入门的php基础系列教程
php入门教程(索引)
smarty获得当前url示例代码
Go 零基础编程入门教程
SEO关键词和基础设施策略
smarty结合xajax检测用户名

[关闭]
~ ~