`
cakin24
  • 浏览: 1396003 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

Smart网站公告

    博客分类:
  • PHP
阅读更多

一 代码

1、创建config.php
<?php
/*  定义服务器的绝对路径  */
define('BASE_PATH',$_SERVER['DOCUMENT_ROOT']);
/*  定义Smarty目录的绝对路径  */
define('SMARTY_PATH','\test\29\12\Smarty\\');
/*  加载Smarty类库文件    */
require BASE_PATH.SMARTY_PATH.'Smarty.class.php';
/*  实例化一个Smarty对象  */
$smarty = new Smarty;
/*  定义各个目录的路径    */
$smarty->template_dir = BASE_PATH.SMARTY_PATH.'templates/';
$smarty->compile_dir = BASE_PATH.SMARTY_PATH.'templates_c/';
$smarty->config_dir = BASE_PATH.SMARTY_PATH.'configs/';
$smarty->cache_dir = BASE_PATH.SMARTY_PATH.'cache/';
/*  调试控制台  */
//$smarty->debugging = true;
/*  Smarty缓存 */
//$Smarty->caching = true;
/*  定义定界符  */
//$smarty->left_delimiter = '<{';
//$smarty->right_delimiter = '}>';
?>
 
2、创建入口页面index.php
<?php
	include_once "conn/conn.php";		//连接数据库
	include_once "config.php";			//调用配置文件
	$sql = "select id,title from tb_public order by id";	//编写查询语句
	$num = 4;
	$rst = $conn->SelectLimit($sql,$num);					//执行查询操作
	$arr = $rst->GetAssoc();								//获取结果集
	$smarty->assign('arr',$arr);							//将返回的结果集存储到指定的Smarty模板变量中
	$smarty->display('index.tpl');							//执行模板文件
?>
 
3、创建模板页index.tpl
<link rel="stylesheet" href="css/pub.css" />
<script language="javascript" src="js/links.js"></script>
<table width="210" height="193" border="0" cellpadding="0" cellspacing="0" background="images/shop_06.gif">
	<tr>
		<td height="35" width="17"></td>
        <td width="193" align="left" valign="top" class="exam"></td>
  </tr>
  	<tr>
		<td height="21" width="17"></td>
        <td width="193" align="left" valign="top" class="exam">
         {foreach key=key item=item from=$arr}
         	<a href="#" class="lk" onclick="return showme({$key},'showpub.php');" ><img src="images/man.JPG" width="14" height="11" border="0" />{$item}</a><br />
         {/foreach}
      </td>
  </tr>
  <tr>
		<td height="20" width="17"></td>
        <td width="193" align="left" valign="bottom" class="exam"></td>
  </tr>
</table>
 
4、创建links.js,定义showme()函数
function showme(key,wurl){
	var purl = wurl + "?id="+key;
	open(purl,'_blank','width=450 height=200',false);
	return false;
}
 
5、创建showpub.php
<?php
	include_once 'conn/conn.php';
	include_once 'config.php';
	$id = $_GET['id'];
	$sql = "select * from tb_public where id = ".$_GET['id'];
	$rst = $conn->execute($sql);
	$arr = $rst->getAssoc();
	$smarty->assign('title','查看公告');
	$smarty->assign('arr',$arr[$id]);
	$smarty->display('showpub.tpl');
?>
 
6、创建showpub.tpl模板页
<title>{$title}</title>
<link rel="stylesheet" href="css/table.css" />
<table width="400" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td colspan="2" height="25" align="center" valign="middle" class="first">公告信息</td>
</tr>
  <tr>
    <td width="70%" height="25" align="center" valign="middle" class="left">标题:{$arr.title}</td>
    <td width="30%" height="25" align="center" valign="middle" class="right">&nbsp;{$arr.addtime}</td>
  </tr>
  <tr>
    <td height="100" colspan="2" align="left" valign="top" class="all" style=" text-indent: 10px;"><br>&nbsp;{$arr.content}</td>
  </tr>
</table>
 
二 运行结果

 

 

  • 大小: 17.2 KB
1
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics